[Groonga-commit] groonga/grnxx at 2d3778b [master] Add grnxx::Storage::num_nodes().

Back to archive index

susumu.yata null+****@clear*****
Fri May 24 10:55:04 JST 2013


susumu.yata	2013-05-24 10:55:04 +0900 (Fri, 24 May 2013)

  New Revision: 2d3778bef697c5e82cbb2bdbdb0ce63b4b7d8560
  https://github.com/groonga/grnxx/commit/2d3778bef697c5e82cbb2bdbdb0ce63b4b7d8560

  Message:
    Add grnxx::Storage::num_nodes().

  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 (+3 -1)
===================================================================
--- lib/grnxx/storage.hpp    2013-05-24 10:38:59 +0900 (b8ee8b4)
+++ lib/grnxx/storage.hpp    2013-05-24 10:55:04 +0900 (4dded33)
@@ -183,7 +183,9 @@ 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.
+  // Return the number of active or unlinked nodes.
+  virtual uint32_t num_nodes() const = 0;
+  // Return the total usage of body chunks (including unlinked nodes).
   virtual uint64_t body_usage() const = 0;
   // Return the total size of body chunks.
   virtual uint64_t body_size() const = 0;

  Modified: lib/grnxx/storage/header.cpp (+3 -1)
===================================================================
--- lib/grnxx/storage/header.cpp    2013-05-24 10:38:59 +0900 (71df1d0)
+++ lib/grnxx/storage/header.cpp    2013-05-24 10:55:04 +0900 (b7625c2)
@@ -43,7 +43,9 @@ Header::Header()
       num_small_body_chunks(0),
       reserved_0(0),
       num_nodes(0),
+      num_active_or_unlinked_nodes(0),
       max_num_nodes(0),
+      reserved_1(0),
       body_usage(0),
       body_size(0),
       total_size(0),
@@ -52,7 +54,7 @@ Header::Header()
       oldest_idle_node_ids(),
       data_mutex(MUTEX_UNLOCKED),
       file_mutex(MUTEX_UNLOCKED),
-      reserved_1{} {
+      reserved_2{} {
   std::memcpy(version, GRNXX_STORAGE_HEADER_VERSION, HEADER_VERSION_SIZE);
   for (size_t i = 0; i < NUM_IDLE_NODE_LISTS; ++i) {
     oldest_idle_node_ids[i] = STORAGE_INVALID_NODE_ID;

  Modified: lib/grnxx/storage/header.hpp (+4 -1)
===================================================================
--- lib/grnxx/storage/header.hpp    2013-05-24 10:38:59 +0900 (3eaec56)
+++ lib/grnxx/storage/header.hpp    2013-05-24 10:55:04 +0900 (3717aaa)
@@ -53,9 +53,12 @@ struct Header {
   uint16_t reserved_0;
   // The number of nodes.
   uint32_t num_nodes;
+  // The number of active or unlinked nodes.
+  uint32_t num_active_or_unlinked_nodes;
   // The upper limit of the number of nodes.
   // This value is extended when a node header chunk is added.
   uint32_t max_num_nodes;
+  uint32_t reserved_1;
   // The total usage of body chunks.
   uint64_t body_usage;
   // The total size of body chunks.
@@ -75,7 +78,7 @@ struct Header {
   Mutex data_mutex;
   // A mutex object for exclusively update files.
   Mutex file_mutex;
-  uint8_t reserved_1[128];
+  uint8_t reserved_2[120];
 
   // Initialize the members except "format".
   Header();

  Modified: lib/grnxx/storage/storage_impl.cpp (+6 -0)
===================================================================
--- lib/grnxx/storage/storage_impl.cpp    2013-05-24 10:38:59 +0900 (1b12f4b)
+++ lib/grnxx/storage/storage_impl.cpp    2013-05-24 10:55:04 +0900 (a852bb0)
@@ -373,6 +373,10 @@ uint16_t StorageImpl::max_num_files() const {
   return header_->max_num_files;
 }
 
+uint32_t StorageImpl::num_nodes() const {
+  return header_->num_active_or_unlinked_nodes;
+}
+
 uint64_t StorageImpl::body_usage() const {
   return header_->body_usage;
 }
@@ -706,6 +710,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_->num_active_or_unlinked_nodes;
   header_->body_usage += node_header->size;
   return true;
 }
@@ -790,6 +795,7 @@ bool StorageImpl::sweep_subtree(NodeHeader *node_header) {
   }
   node_header->status = STORAGE_NODE_IDLE;
   node_header->modified_time = clock_.now();
+  --header_->num_active_or_unlinked_nodes;
   header_->body_usage -= node_header->size;
   register_idle_node(node_header);
   if (node_header->next_node_id != STORAGE_INVALID_NODE_ID) {

  Modified: lib/grnxx/storage/storage_impl.hpp (+1 -0)
===================================================================
--- lib/grnxx/storage/storage_impl.hpp    2013-05-24 10:38:59 +0900 (eccb126)
+++ lib/grnxx/storage/storage_impl.hpp    2013-05-24 10:55:04 +0900 (64470f0)
@@ -65,6 +65,7 @@ class StorageImpl : public Storage {
   StorageFlags flags() const;
   uint64_t max_file_size() const;
   uint16_t max_num_files() const;
+  uint32_t num_nodes() const;
   uint64_t body_usage() const;
   uint64_t body_size() const;
   uint64_t total_size() const;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index