Eliminate reserveSpace flag
This commit is contained in:
		
							parent
							
								
									5a64e66268
								
							
						
					
					
						commit
						28e7e29abd
					
				
					 10 changed files with 33 additions and 37 deletions
				
			
		|  | @ -608,6 +608,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) | ||||||
| 
 | 
 | ||||||
|     state.shouldDelete = options.action == GCOptions::gcDeleteDead || options.action == GCOptions::gcDeleteSpecific; |     state.shouldDelete = options.action == GCOptions::gcDeleteDead || options.action == GCOptions::gcDeleteSpecific; | ||||||
| 
 | 
 | ||||||
|  |     if (state.shouldDelete && pathExists(reservedPath)) | ||||||
|  |         deletePath(reservedPath); | ||||||
|  | 
 | ||||||
|     /* Acquire the global GC root.  This prevents
 |     /* Acquire the global GC root.  This prevents
 | ||||||
|        a) New roots from being added. |        a) New roots from being added. | ||||||
|        b) Processes from creating new temporary root files. */ |        b) Processes from creating new temporary root files. */ | ||||||
|  |  | ||||||
|  | @ -216,8 +216,9 @@ void checkStoreNotSymlink() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| LocalStore::LocalStore(bool reserveSpace) | LocalStore::LocalStore() | ||||||
|     : didSetSubstituterEnv(false) |     : reservedPath(settings.nixDBPath + "/reserved") | ||||||
|  |     , didSetSubstituterEnv(false) | ||||||
| { | { | ||||||
|     schemaPath = settings.nixDBPath + "/schema"; |     schemaPath = settings.nixDBPath + "/schema"; | ||||||
| 
 | 
 | ||||||
|  | @ -276,25 +277,20 @@ LocalStore::LocalStore(bool reserveSpace) | ||||||
|        needed, we reserve some dummy space that we can free just |        needed, we reserve some dummy space that we can free just | ||||||
|        before doing a garbage collection. */ |        before doing a garbage collection. */ | ||||||
|     try { |     try { | ||||||
|         Path reservedPath = settings.nixDBPath + "/reserved"; |         struct stat st; | ||||||
|         if (reserveSpace) { |         if (stat(reservedPath.c_str(), &st) == -1 || | ||||||
|             struct stat st; |             st.st_size != settings.reservedSize) | ||||||
|             if (stat(reservedPath.c_str(), &st) == -1 || |         { | ||||||
|                 st.st_size != settings.reservedSize) |             AutoCloseFD fd = open(reservedPath.c_str(), O_WRONLY | O_CREAT, 0600); | ||||||
|             { |             int res = -1; | ||||||
|                 AutoCloseFD fd = open(reservedPath.c_str(), O_WRONLY | O_CREAT, 0600); |  | ||||||
|                 int res = -1; |  | ||||||
| #if HAVE_POSIX_FALLOCATE | #if HAVE_POSIX_FALLOCATE | ||||||
|                 res = posix_fallocate(fd, 0, settings.reservedSize); |             res = posix_fallocate(fd, 0, settings.reservedSize); | ||||||
| #endif | #endif | ||||||
|                 if (res == -1) { |             if (res == -1) { | ||||||
|                     writeFull(fd, string(settings.reservedSize, 'X')); |                 writeFull(fd, string(settings.reservedSize, 'X')); | ||||||
|                     ftruncate(fd, settings.reservedSize); |                 ftruncate(fd, settings.reservedSize); | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else |  | ||||||
|             deletePath(reservedPath); |  | ||||||
|     } catch (SysError & e) { /* don't care about errors */ |     } catch (SysError & e) { /* don't care about errors */ | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -88,11 +88,13 @@ private: | ||||||
| 
 | 
 | ||||||
|     Path linksDir; |     Path linksDir; | ||||||
| 
 | 
 | ||||||
|  |     Path reservedPath; | ||||||
|  | 
 | ||||||
| public: | public: | ||||||
| 
 | 
 | ||||||
|     /* Initialise the local store, upgrading the schema if
 |     /* Initialise the local store, upgrading the schema if
 | ||||||
|        necessary. */ |        necessary. */ | ||||||
|     LocalStore(bool reserveSpace = true); |     LocalStore(); | ||||||
| 
 | 
 | ||||||
|     ~LocalStore(); |     ~LocalStore(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -49,7 +49,7 @@ RemoteStore::RemoteStore(size_t maxConnections) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace) | ref<RemoteStore::Connection> RemoteStore::openConnection() | ||||||
| { | { | ||||||
|     auto conn = make_ref<Connection>(); |     auto conn = make_ref<Connection>(); | ||||||
| 
 | 
 | ||||||
|  | @ -106,7 +106,7 @@ ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 11) |         if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 11) | ||||||
|             conn->to << reserveSpace; |             conn->to << false; | ||||||
| 
 | 
 | ||||||
|         conn->processStderr(); |         conn->processStderr(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -106,7 +106,7 @@ private: | ||||||
| 
 | 
 | ||||||
|     ref<Pool<Connection>> connections; |     ref<Pool<Connection>> connections; | ||||||
| 
 | 
 | ||||||
|     ref<Connection> openConnection(bool reserveSpace = true); |     ref<Connection> openConnection(); | ||||||
| 
 | 
 | ||||||
|     void setOptions(ref<Connection> conn); |     void setOptions(ref<Connection> conn); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -320,7 +320,7 @@ void Store::exportPaths(const Paths & paths, | ||||||
| namespace nix { | namespace nix { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ref<Store> openStoreAt(const std::string & uri, bool reserveSpace) | ref<Store> openStoreAt(const std::string & uri) | ||||||
| { | { | ||||||
|     if (std::string(uri, 0, 7) == "file://") { |     if (std::string(uri, 0, 7) == "file://") { | ||||||
|         auto store = make_ref<LocalBinaryCacheStore>(std::shared_ptr<Store>(0), |         auto store = make_ref<LocalBinaryCacheStore>(std::shared_ptr<Store>(0), | ||||||
|  | @ -345,13 +345,13 @@ ref<Store> openStoreAt(const std::string & uri, bool reserveSpace) | ||||||
| 
 | 
 | ||||||
|     return mode == mDaemon |     return mode == mDaemon | ||||||
|         ? (ref<Store>) make_ref<RemoteStore>() |         ? (ref<Store>) make_ref<RemoteStore>() | ||||||
|         : (ref<Store>) make_ref<LocalStore>(reserveSpace); |         : (ref<Store>) make_ref<LocalStore>(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ref<Store> openStore(bool reserveSpace) | ref<Store> openStore() | ||||||
| { | { | ||||||
|     return openStoreAt(getEnv("NIX_REMOTE"), reserveSpace); |     return openStoreAt(getEnv("NIX_REMOTE")); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -432,16 +432,12 @@ void removeTempRoots(); | ||||||
| 
 | 
 | ||||||
|    If ‘uri’ is empty, it defaults to ‘direct’ or ‘daemon’ depending on |    If ‘uri’ is empty, it defaults to ‘direct’ or ‘daemon’ depending on | ||||||
|    whether the user has write access to the local Nix store/database. |    whether the user has write access to the local Nix store/database. | ||||||
| 
 |    set to true *unless* you're going to collect garbage. */ | ||||||
|    The Boolean ‘reserveSpace’ denotes whether some disk space should | ref<Store> openStoreAt(const std::string & uri); | ||||||
|    be reserved to enable future garbage collector runs. It should be |  | ||||||
|    set to true *unless* you're going to collect garbage. |  | ||||||
| */ |  | ||||||
| ref<Store> openStoreAt(const std::string & uri, bool reserveSpace = true); |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /* Open the store indicated by the ‘NIX_REMOTE’ environment variable. */ | /* Open the store indicated by the ‘NIX_REMOTE’ environment variable. */ | ||||||
| ref<Store> openStore(bool reserveSpace = true); | ref<Store> openStore(); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /* Display a set of paths in human-readable form (i.e., between quotes
 | /* Display a set of paths in human-readable form (i.e., between quotes
 | ||||||
|  |  | ||||||
|  | @ -82,7 +82,7 @@ int main(int argc, char * * argv) | ||||||
| 
 | 
 | ||||||
|         // Run the actual garbage collector.
 |         // Run the actual garbage collector.
 | ||||||
|         if (!dryRun) { |         if (!dryRun) { | ||||||
|             auto store = openStore(false); |             auto store = openStore(); | ||||||
|             options.action = GCOptions::gcDeleteDead; |             options.action = GCOptions::gcDeleteDead; | ||||||
|             GCResults results; |             GCResults results; | ||||||
|             PrintFreed freed(true, results); |             PrintFreed freed(true, results); | ||||||
|  |  | ||||||
|  | @ -562,9 +562,8 @@ static void processConnection(bool trusted) | ||||||
|     if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) |     if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) | ||||||
|         setAffinityTo(readInt(from)); |         setAffinityTo(readInt(from)); | ||||||
| 
 | 
 | ||||||
|     bool reserveSpace = true; |  | ||||||
|     if (GET_PROTOCOL_MINOR(clientVersion) >= 11) |     if (GET_PROTOCOL_MINOR(clientVersion) >= 11) | ||||||
|         reserveSpace = readInt(from) != 0; |         readInt(from); // obsolete reserveSpace
 | ||||||
| 
 | 
 | ||||||
|     /* Send startup error messages to the client. */ |     /* Send startup error messages to the client. */ | ||||||
|     startWork(); |     startWork(); | ||||||
|  | @ -582,7 +581,7 @@ static void processConnection(bool trusted) | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|         /* Open the store. */ |         /* Open the store. */ | ||||||
|         auto store = make_ref<LocalStore>(reserveSpace); |         auto store = make_ref<LocalStore>(); | ||||||
| 
 | 
 | ||||||
|         stopWork(); |         stopWork(); | ||||||
|         to.flush(); |         to.flush(); | ||||||
|  |  | ||||||
|  | @ -1131,7 +1131,7 @@ int main(int argc, char * * argv) | ||||||
|         if (!op) throw UsageError("no operation specified"); |         if (!op) throw UsageError("no operation specified"); | ||||||
| 
 | 
 | ||||||
|         if (op != opDump && op != opRestore) /* !!! hack */ |         if (op != opDump && op != opRestore) /* !!! hack */ | ||||||
|             store = openStore(op != opGC); |             store = openStore(); | ||||||
| 
 | 
 | ||||||
|         op(opFlags, opArgs); |         op(opFlags, opArgs); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue