susumu.yata
null+****@clear*****
Sun Apr 28 23:01:48 JST 2013
susumu.yata 2013-04-28 23:01:48 +0900 (Sun, 28 Apr 2013) New Revision: 9e66ccd46996ab0c66f4644e5c4ca4ea2a7762a8 https://github.com/groonga/grnxx/commit/9e66ccd46996ab0c66f4644e5c4ca4ea2a7762a8 Message: Update the interface of grnxx::Storage. Modified files: lib/grnxx/storage.hpp lib/grnxx/storage/storage_impl.cpp lib/grnxx/storage/storage_impl.hpp test/test_storage.cpp Modified: lib/grnxx/storage.hpp (+9 -3) =================================================================== --- lib/grnxx/storage.hpp 2013-04-28 21:39:27 +0900 (f75ba47) +++ lib/grnxx/storage.hpp 2013-04-28 23:01:48 +0900 (54452a1) @@ -141,9 +141,9 @@ class Storage { StorageFlags flags = STORAGE_DEFAULT); // Open or create a storage. // The available flags is STORAGE_HUGE_TLB. - static Storage *open_or_create(const char *path, - StorageFlags flags = STORAGE_DEFAULT, - const StorageOptions &options = StorageOptions()); + static Storage *open_or_create( + const char *path, StorageFlags flags = STORAGE_DEFAULT, + const StorageOptions &options = StorageOptions()); // Return true iff "path" refers to a valid storage. static bool exists(const char *path); @@ -167,6 +167,12 @@ class Storage { virtual const char *path() const = 0; // Return the activated flags. virtual StorageFlags flags() const = 0; + // Return the maximum size of each file. + virtual uint64_t max_file_size() const = 0; + // Return the maximum number of files. + virtual uint16_t max_num_files() const = 0; + // Return the total size. + virtual uint64_t total_size() const = 0; // TODO: Member functions to get details, such as total size, #nodes, etc. }; Modified: lib/grnxx/storage/storage_impl.cpp (+15 -6) =================================================================== --- lib/grnxx/storage/storage_impl.cpp 2013-04-28 21:39:27 +0900 (32e2418) +++ lib/grnxx/storage/storage_impl.cpp 2013-04-28 23:01:48 +0900 (d790c82) @@ -54,8 +54,6 @@ static_assert(MAX_NUM_NODE_BODY_CHUNKS >= 2000, constexpr uint64_t NODE_BODY_MIN_CHUNK_SIZE = 1 << 21; constexpr double NODE_BODY_CHUNK_SIZE_RATIO = 1.0 / 64; -// TODO: Define constant values. - } // namespace StorageImpl::StorageImpl() @@ -235,6 +233,18 @@ StorageFlags StorageImpl::flags() const { return flags_; } +uint64_t StorageImpl::max_file_size() const { + return header_->max_file_size; +} + +uint16_t StorageImpl::max_num_files() const { + return header_->max_num_files; +} + +uint64_t StorageImpl::total_size() const { + return header_->total_size; +} + bool StorageImpl::create_file_backed_storage(const char *path, StorageFlags flags, const StorageOptions &options) { @@ -358,7 +368,6 @@ bool StorageImpl::open_or_create_storage(const char *path, StorageFlags flags, std::unique_ptr<File> header_file(File::open(path)); if (header_file) { // Open an existing storage. - // TODO: If another thread or process is creating the storage? std::unique_ptr<Chunk> header_chunk( create_chunk(header_file.get(), 0, HEADER_CHUNK_SIZE)); if (!header_chunk) { @@ -864,9 +873,9 @@ File *StorageImpl::get_file(uint16_t file_id) { } char *StorageImpl::generate_path(uint16_t file_id) { - // If path_ ends with ".grn", the result also ends with ".grn". - // In this case, file_id is inserted before the ".grn". - // Otherwise, file_id is appended as a suffix. + // If "path_" ends with ".grn", the result also ends with ".grn". + // In this case, "file_id" is inserted before the ".grn". + // Otherwise, "file_id" is appended as a suffix. const Slice prefix = path_.get(); const bool has_extension = prefix.ends_with(".grn"); const size_t path_size = prefix.size() + 5; Modified: lib/grnxx/storage/storage_impl.hpp (+3 -0) =================================================================== --- lib/grnxx/storage/storage_impl.hpp 2013-04-28 21:39:27 +0900 (9b2ff61) +++ lib/grnxx/storage/storage_impl.hpp 2013-04-28 23:01:48 +0900 (8186144) @@ -55,6 +55,9 @@ class StorageImpl : public Storage { const char *path() const; StorageFlags flags() const; + uint64_t max_file_size() const; + uint16_t max_num_files() const; + uint64_t total_size() const; // TODO: Member functions to get details, such as total size, #nodes, etc. Modified: test/test_storage.cpp (+31 -0) =================================================================== --- test/test_storage.cpp 2013-04-28 21:39:27 +0900 (226f9f8) +++ test/test_storage.cpp 2013-04-28 23:01:48 +0900 (65bbb71) @@ -574,6 +574,34 @@ void test_storage_flags() { assert(grnxx::Storage::unlink(FILE_PATH)); } +void test_storage_max_file_size() { + grnxx::StorageOptions options; + options.max_file_size = 1ULL << 36; + std::unique_ptr<grnxx::Storage> storage( + grnxx::Storage::create(nullptr, grnxx::STORAGE_DEFAULT, options)); + assert(storage->max_file_size() == options.max_file_size); +} + +void test_storage_max_num_files() { + grnxx::StorageOptions options; + options.max_num_files = 100; + std::unique_ptr<grnxx::Storage> storage( + grnxx::Storage::create(nullptr, grnxx::STORAGE_DEFAULT, options)); + assert(storage->max_num_files() == options.max_num_files); +} + +void test_storage_total_size() { + uint64_t prev_total_size = 0; + std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); + assert(storage->total_size() > prev_total_size); + prev_total_size = storage->total_size(); + for (int i = 0; i < 16; ++i) { + storage->create_node(grnxx::STORAGE_ROOT_NODE_ID, 1 << 24); + assert(storage->total_size() > prev_total_size); + prev_total_size = storage->total_size(); + } +} + void test_path() { test_full_path(); test_unique_path(); @@ -611,6 +639,9 @@ void test_storage() { test_storage_sweep(); test_storage_path(); test_storage_flags(); + test_storage_max_file_size(); + test_storage_max_num_files(); + test_storage_total_size(); } } // namespace -------------- next part -------------- HTML����������������������������...Download