[Groonga-commit] groonga/grnxx at 59b2989 [master] Add grnxx::storage::Header.

Back to archive index

susumu.yata null+****@clear*****
Wed Apr 24 13:59:13 JST 2013


susumu.yata	2013-04-24 13:59:13 +0900 (Wed, 24 Apr 2013)

  New Revision: 59b2989b6ff95eb188be7135b4222f2e49dfd58b
  https://github.com/groonga/grnxx/commit/59b2989b6ff95eb188be7135b4222f2e49dfd58b

  Message:
    Add grnxx::storage::Header.

  Added files:
    lib/grnxx/storage/header.cpp
    lib/grnxx/storage/header.hpp
  Modified files:
    lib/grnxx/storage/Makefile.am

  Modified: lib/grnxx/storage/Makefile.am (+2 -0)
===================================================================
--- lib/grnxx/storage/Makefile.am    2013-04-24 13:56:05 +0900 (92c1198)
+++ lib/grnxx/storage/Makefile.am    2013-04-24 13:59:13 +0900 (244f998)
@@ -6,6 +6,7 @@ libgrnxx_storage_la_SOURCES =		\
 	file.cpp			\
 	file-posix.cpp			\
 	file-windows.cpp		\
+	header.cpp			\
 	node_header.cpp			\
 	path.cpp			\
 	storage_impl.cpp		\
@@ -18,6 +19,7 @@ libgrnxx_storage_include_HEADERS =	\
 	file.hpp			\
 	file-posix.hpp			\
 	file-windows.hpp		\
+	header.hpp			\
 	node_header.hpp			\
 	path.hpp			\
 	storage_impl.hpp		\

  Added: lib/grnxx/storage/header.cpp (+61 -0) 100644
===================================================================
--- /dev/null
+++ lib/grnxx/storage/header.cpp    2013-04-24 13:59:13 +0900 (ec34009)
@@ -0,0 +1,61 @@
+/*
+  Copyright (C) 2012-2013  Brazil, Inc.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#include "grnxx/storage/header.hpp"
+
+#include "grnxx/version.h"
+
+#define GRNXX_STORAGE_HEADER_FORMAT  "grnxx::Storage"
+#define GRNXX_STORAGE_HEADER_VERSION GRNXX_VERSION
+
+namespace grnxx {
+namespace storage {
+namespace {
+
+// For comparison.
+constexpr char HEADER_FORMAT[HEADER_FORMAT_SIZE] = GRNXX_STORAGE_HEADER_FORMAT;
+
+}  // namespace
+
+Header::Header()
+    : format{ GRNXX_STORAGE_HEADER_FORMAT },
+      version{ GRNXX_STORAGE_HEADER_VERSION },
+      max_num_files(0),
+      max_file_size(0),
+      total_size(0),
+      num_files(0),
+      num_node_chunks(0),
+      num_nodes(0),
+      max_num_nodes(0),
+      latest_phantom_node_id(INVALID_NODE_ID),
+      latest_unlinked_node_id(INVALID_NODE_ID),
+      oldest_idle_node_ids(),
+      inter_process_data_mutex(MUTEX_UNLOCKED),
+      inter_process_file_mutex(MUTEX_UNLOCKED) {
+  static constexpr size_t NUM_LISTS =
+      sizeof(oldest_idle_node_ids) / sizeof(*oldest_idle_node_ids);
+  for (size_t i = 0; i < NUM_LISTS; ++i) {
+    oldest_idle_node_ids[i] = INVALID_NODE_ID;
+  }
+}
+
+bool Header::is_valid() const {
+  return std::memcmp(format, HEADER_FORMAT, HEADER_FORMAT_SIZE) == 0;
+}
+
+}  // namespace storage
+}  // namespace grnxx

  Added: lib/grnxx/storage/header.hpp (+80 -0) 100644
===================================================================
--- /dev/null
+++ lib/grnxx/storage/header.hpp    2013-04-24 13:59:13 +0900 (dcc5e6d)
@@ -0,0 +1,80 @@
+/*
+  Copyright (C) 2012-2013  Brazil, Inc.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#ifndef GRNXX_STORAGE_HEADER_HPP
+#define GRNXX_STORAGE_HEADER_HPP
+
+#include "grnxx/basic.hpp"
+#include "grnxx/mutex.hpp"
+#include "grnxx/storage.hpp"
+
+namespace grnxx {
+namespace storage {
+
+// The number of bytes allocated to a header.
+// sizeof(Header) must not be greater than this value.
+constexpr size_t HEADER_SIZE         = 512;
+
+// The buffer size allocated for the format identifier.
+constexpr size_t HEADER_FORMAT_SIZE  = 32;
+// The buffer size allocated for the version string.
+constexpr size_t HEADER_VERSION_SIZE = 32;
+
+struct Header {
+  // The identifier for checking the file format.
+  char format[HEADER_FORMAT_SIZE];
+  // The grnxx version.
+  char version[HEADER_VERSION_SIZE];
+  // The maximum number of files.
+  uint64_t max_num_files;
+  // The maximum size of each file.
+  uint64_t max_file_size;
+  // The total size including headers.
+  uint64_t total_size;
+  // The number of files.
+  uint32_t num_files;
+  // The number of node chunks.
+  uint32_t num_node_chunks;
+  // The number of nodes.
+  uint32_t num_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;
+  // The ID of the latest phantom node.
+  uint32_t latest_phantom_node_id;
+  // The ID of the latest unlinked node.
+  uint32_t latest_unlinked_node_id;
+  // The IDs of the oldest idle nodes.
+  uint32_t oldest_idle_node_ids[64];
+  // A mutex object for exclusively updating data.
+  Mutex inter_process_data_mutex;
+  // A mutex object for exclusively update files.
+  Mutex inter_process_file_mutex;
+
+  // Initialize the members.
+  Header();
+
+  // Return true if the header seems to be correct.
+  bool is_valid() const;
+};
+
+static_assert(sizeof(Header) <= HEADER_SIZE, "sizeof(Header) > HEADER_SIZE");
+
+}  // namespace storage
+}  // namespace grnxx
+
+#endif  // GRNXX_STORAGE_HEADER_HPP
-------------- next part --------------
HTML����������������������������...
Download 



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