[Groonga-commit] groonga/grnxx at d72b921 [master] Add body_usage() and body_size() to grnxx::Storage.

アーカイブの一覧に戻る

susumu.yata null+****@clear*****
Thu May 23 14:41:27 JST 2013


susumu.yata	2013-05-23 14:41:27 +0900 (Thu, 23 May 2013)

  New Revision: d72b921d0b444542efc679d0ba395e8101c86634
  https://github.com/groonga/grnxx/commit/d72b921d0b444542efc679d0ba395e8101c86634

  Message:
    Add body_usage() and body_size() to grnxx::Storage.

  Modified files:
    lib/grnxx/storage.hpp
    lib/grnxx/storage/header.cpp
    lib/grnxx/storage/header.hpp
    lib/grnxx/storage/storage_impl.cpp
    lib/grnxx/storage/storage_impl.hpp

  Modified: lib/grnxx/storage.hpp (+4 -0)
===================================================================
--- lib/grnxx/storage.hpp    2013-05-22 16:18:28 +0900 (228b44a)
+++ lib/grnxx/storage.hpp    2013-05-23 14:41:27 +0900 (b8ee8b4)
@@ -183,6 +183,10 @@ class Storage {
   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 usage of body chunks.
+  virtual uint64_t body_usage() const = 0;
+  // Return the total size of body chunks.
+  virtual uint64_t body_size() const = 0;
   // Return the total size.
   virtual uint64_t total_size() const = 0;
 };

  Modified: lib/grnxx/storage/header.cpp (+2 -0)
===================================================================
--- lib/grnxx/storage/header.cpp    2013-05-22 16:18:28 +0900 (c596ce2)
+++ lib/grnxx/storage/header.cpp    2013-05-23 14:41:27 +0900 (71df1d0)
@@ -44,6 +44,8 @@ Header::Header()
       reserved_0(0),
       num_nodes(0),
       max_num_nodes(0),
+      body_usage(0),
+      body_size(0),
       total_size(0),
       latest_phantom_node_id(STORAGE_INVALID_NODE_ID),
       latest_unlinked_node_id(STORAGE_INVALID_NODE_ID),

  Modified: lib/grnxx/storage/header.hpp (+5 -1)
===================================================================
--- lib/grnxx/storage/header.hpp    2013-05-22 16:18:28 +0900 (5399f36)
+++ lib/grnxx/storage/header.hpp    2013-05-23 14:41:27 +0900 (3eaec56)
@@ -56,6 +56,10 @@ struct Header {
   // The upper limit of the number of nodes.
   // This value is extended when a node header chunk is added.
   uint32_t max_num_nodes;
+  // The total usage of body chunks.
+  uint64_t body_usage;
+  // The total size of body chunks.
+  uint64_t body_size;
   // The total size including headers.
   uint64_t total_size;
   // The ID of the latest phantom node.
@@ -71,7 +75,7 @@ struct Header {
   Mutex data_mutex;
   // A mutex object for exclusively update files.
   Mutex file_mutex;
-  uint8_t reserved_1[144];
+  uint8_t reserved_1[128];
 
   // Initialize the members except "format".
   Header();

  Modified: lib/grnxx/storage/storage_impl.cpp (+14 -3)
===================================================================
--- lib/grnxx/storage/storage_impl.cpp    2013-05-22 16:18:28 +0900 (cc5c944)
+++ lib/grnxx/storage/storage_impl.cpp    2013-05-23 14:41:27 +0900 (6e415e2)
@@ -345,7 +345,7 @@ bool StorageImpl::sweep(Duration lifetime) {
       return true;
     }
     const uint32_t next_node_id = oldest_node_header->next_unlinked_node_id;
-    if (!sweep_subtree(threshold, oldest_node_header)) {
+    if (!sweep_subtree(oldest_node_header)) {
       return false;
     }
     if (oldest_node_header != latest_node_header) {
@@ -373,6 +373,14 @@ uint16_t StorageImpl::max_num_files() const {
   return header_->max_num_files;
 }
 
+uint64_t StorageImpl::body_usage() const {
+  return header_->body_usage;
+}
+
+uint64_t StorageImpl::body_size() const {
+  return header_->body_size;
+}
+
 uint64_t StorageImpl::total_size() const {
   return header_->total_size;
 }
@@ -687,6 +695,7 @@ bool StorageImpl::activate_idle_node(NodeHeader *node_header) {
   node_header->child_node_id = STORAGE_INVALID_NODE_ID;
   node_header->sibling_node_id = STORAGE_INVALID_NODE_ID;
   node_header->modified_time = clock_.now();
+  header_->body_usage += node_header->size;
   return true;
 }
 
@@ -755,7 +764,7 @@ bool StorageImpl::associate_node_with_chunk(NodeHeader *node_header,
   return true;
 }
 
-bool StorageImpl::sweep_subtree(Time threshold, NodeHeader *node_header) {
+bool StorageImpl::sweep_subtree(NodeHeader *node_header) {
   uint32_t child_node_id = node_header->child_node_id;
   while (child_node_id != STORAGE_INVALID_NODE_ID) {
     NodeHeader * const child_node_header = get_node_header(child_node_id);
@@ -763,13 +772,14 @@ bool StorageImpl::sweep_subtree(Time threshold, NodeHeader *node_header) {
       return false;
     }
     child_node_id = child_node_header->sibling_node_id;
-    if (!sweep_subtree(threshold, child_node_header)) {
+    if (!sweep_subtree(child_node_header)) {
       return false;
     }
     node_header->child_node_id = child_node_id;
   }
   node_header->status = STORAGE_NODE_IDLE;
   node_header->modified_time = clock_.now();
+  header_->body_usage -= node_header->size;
   register_idle_node(node_header);
   if (node_header->next_node_id != STORAGE_INVALID_NODE_ID) {
     NodeHeader * const next_node_header =
@@ -931,6 +941,7 @@ ChunkIndex *StorageImpl::create_body_chunk(uint64_t size) {
   chunk_index->file_id = file_id;
   chunk_index->offset = offset;
   chunk_index->size = size;
+  header_->body_size += size;
   header_->total_size += size;
   ++header_->num_body_chunks;
   return chunk_index;

  Modified: lib/grnxx/storage/storage_impl.hpp (+3 -1)
===================================================================
--- lib/grnxx/storage/storage_impl.hpp    2013-05-22 16:18:28 +0900 (273042f)
+++ lib/grnxx/storage/storage_impl.hpp    2013-05-23 14:41:27 +0900 (eccb126)
@@ -65,6 +65,8 @@ class StorageImpl : public Storage {
   StorageFlags flags() const;
   uint64_t max_file_size() const;
   uint16_t max_num_files() const;
+  uint64_t body_usage() const;
+  uint64_t body_size() const;
   uint64_t total_size() const;
 
  private:
@@ -106,7 +108,7 @@ class StorageImpl : public Storage {
                                 ChunkIndex **remainder_chunk_index);
   ChunkIndex *create_body_chunk(uint64_t size);
 
-  bool sweep_subtree(Time threshold, NodeHeader *node_header);
+  bool sweep_subtree(NodeHeader *node_header);
   bool merge_idle_nodes(NodeHeader *node_header, NodeHeader *next_node_header);
 
   bool register_idle_node(NodeHeader *node_header);
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る