|
MongoDB
2.0.3
|
00001 // @file file_allocator.h 00002 00003 /* Copyright 2009 10gen Inc. 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "../pch.h" 00019 00020 namespace mongo { 00021 00022 /* 00023 * Handles allocation of contiguous files on disk. Allocation may be 00024 * requested asynchronously or synchronously. 00025 * singleton 00026 */ 00027 class FileAllocator : boost::noncopyable { 00028 /* 00029 * The public functions may not be called concurrently. The allocation 00030 * functions may be called multiple times per file, but only the first 00031 * size specified per file will be used. 00032 */ 00033 public: 00034 void start(); 00035 00040 void requestAllocation( const string &name, long &size ); 00041 00042 00047 void allocateAsap( const string &name, unsigned long long &size ); 00048 00049 void waitUntilFinished() const; 00050 00051 bool hasFailed() const; 00052 00053 static void ensureLength(int fd , long size); 00054 00056 static FileAllocator * get(); 00057 00058 private: 00059 00060 FileAllocator(); 00061 00062 #if !defined(_WIN32) 00063 void checkFailure(); 00064 00065 // caller must hold pendingMutex_ lock. Returns size if allocated or 00066 // allocation requested, -1 otherwise. 00067 long prevSize( const string &name ) const; 00068 00069 // caller must hold pendingMutex_ lock. 00070 bool inProgress( const string &name ) const; 00071 00073 static void run( FileAllocator * fa ); 00074 00075 mutable mongo::mutex _pendingMutex; 00076 mutable boost::condition _pendingUpdated; 00077 00078 list< string > _pending; 00079 mutable map< string, long > _pendingSize; 00080 00081 bool _failed; 00082 #endif 00083 00084 static FileAllocator* _instance; 00085 00086 }; 00087 00089 boost::filesystem::path ensureParentDirCreated(const boost::filesystem::path& p); 00090 00091 } // namespace mongo
1.8.0