From 07dda3eb26841cfb394d0590957ce6aac1a02e7a Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 23 Jul 2013 13:23:07 -0700 Subject: [PATCH] Import KeyvaDB to Beast --- Builds/QtCreator/rippled.pro | 1 + Builds/VisualStudio2012/RippleD.vcxproj | 1 + .../VisualStudio2012/RippleD.vcxproj.filters | 3 + SConstruct | 1 + .../Builds/VisualStudio2012/beast.vcxproj | 15 +++++ .../VisualStudio2012/beast.vcxproj.filters | 21 +++++++ Subtrees/beast/modules/beast_db/beast_db.cpp | 31 +++++++++++ Subtrees/beast/modules/beast_db/beast_db.h | 52 ++++++++++++++++++ Subtrees/beast/modules/beast_db/beast_db.mm | 20 +++++++ .../beast_db/keyvalue/beast_KeyvaDB.cpp | 24 ++++++-- .../modules/beast_db/keyvalue/beast_KeyvaDB.h | 55 +++++++++++++++++++ TODO.txt | 5 +- modules/ripple_app/node/ripple_KeyvaDB.h | 40 -------------- modules/ripple_app/ripple_app.cpp | 4 +- 14 files changed, 225 insertions(+), 48 deletions(-) create mode 100644 Subtrees/beast/modules/beast_db/beast_db.cpp create mode 100644 Subtrees/beast/modules/beast_db/beast_db.h create mode 100644 Subtrees/beast/modules/beast_db/beast_db.mm rename modules/ripple_app/node/ripple_KeyvaDB.cpp => Subtrees/beast/modules/beast_db/keyvalue/beast_KeyvaDB.cpp (96%) create mode 100644 Subtrees/beast/modules/beast_db/keyvalue/beast_KeyvaDB.h delete mode 100644 modules/ripple_app/node/ripple_KeyvaDB.h diff --git a/Builds/QtCreator/rippled.pro b/Builds/QtCreator/rippled.pro index 89ebd28df4..9858ac395a 100644 --- a/Builds/QtCreator/rippled.pro +++ b/Builds/QtCreator/rippled.pro @@ -63,6 +63,7 @@ SOURCES += \ ../../Subtrees/beast/modules/beast_basics/beast_basics.cpp \ ../../Subtrees/beast/modules/beast_core/beast_core.cpp \ ../../Subtrees/beast/modules/beast_crypto/beast_crypto.cpp \ + ../../Subtrees/beast/modules/beast_db/beast_db.cpp \ ../../modules/ripple_app/ripple_app_pt1.cpp \ ../../modules/ripple_app/ripple_app_pt2.cpp \ ../../modules/ripple_app/ripple_app_pt3.cpp \ diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index 10595bf0b0..bdf45f6cc1 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -1039,6 +1039,7 @@ + true true diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 63a4e3ae69..beaa45d3af 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -903,6 +903,9 @@ [1] Ripple\ripple_app\node + + [0] Subtrees\beast + diff --git a/SConstruct b/SConstruct index 903d5bf877..69461f7c6f 100644 --- a/SConstruct +++ b/SConstruct @@ -122,6 +122,7 @@ COMPILED_FILES = [ 'Subtrees/beast/modules/beast_basics/beast_basics.cpp', 'Subtrees/beast/modules/beast_core/beast_core.cpp', 'Subtrees/beast/modules/beast_crypto/beast_crypto.cpp', + 'Subtrees/beast/modules/beast_db/beast_db.cpp', 'modules/ripple_app/ripple_app_pt1.cpp', 'modules/ripple_app/ripple_app_pt2.cpp', 'modules/ripple_app/ripple_app_pt3.cpp', diff --git a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj index b53c3918ec..99c88c4500 100644 --- a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj +++ b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj @@ -78,6 +78,12 @@ true true + + true + true + true + true + @@ -249,6 +255,8 @@ + + @@ -933,6 +941,13 @@ true true + + + true + true + true + true + diff --git a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters index 2692e37621..7f02acb998 100644 --- a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters @@ -36,6 +36,9 @@ beast_basics + + beast_db + @@ -125,6 +128,12 @@ {1170f2bc-2456-410a-ab2b-c45f6ed37b9e} + + {4834218f-f13f-41bc-a8a0-50314a3a99a3} + + + {15a98fee-1b52-45eb-9480-514b8750d755} + @@ -632,6 +641,12 @@ beast_core\memory + + beast_db + + + beast_db\keyvalue + @@ -982,6 +997,12 @@ beast_core\diagnostic + + beast_db + + + beast_db\keyvalue + diff --git a/Subtrees/beast/modules/beast_db/beast_db.cpp b/Subtrees/beast/modules/beast_db/beast_db.cpp new file mode 100644 index 0000000000..622c2afdbd --- /dev/null +++ b/Subtrees/beast/modules/beast_db/beast_db.cpp @@ -0,0 +1,31 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include "BeastConfig.h" + +#include "beast_db.h" + +#include "../beast_crypto/beast_crypto.h" + +namespace beast +{ + +#include "keyvalue/beast_KeyvaDB.cpp" + +} diff --git a/Subtrees/beast/modules/beast_db/beast_db.h b/Subtrees/beast/modules/beast_db/beast_db.h new file mode 100644 index 0000000000..1612a178d9 --- /dev/null +++ b/Subtrees/beast/modules/beast_db/beast_db.h @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_BEAST_DB_H_INCLUDED +#define BEAST_BEAST_DB_H_INCLUDED + +//------------------------------------------------------------------------------ + +/* If you fail to make sure that all your compile units are building Beast with + the same set of option flags, then there's a risk that different compile + units will treat the classes as having different memory layouts, leading to + very nasty memory corruption errors when they all get linked together. + That's why it's best to always include the BeastConfig.h file before any + beast headers. +*/ +#ifndef BEAST_BEASTCONFIG_H_INCLUDED +# ifdef _MSC_VER +# pragma message ("Have you included your BeastConfig.h file before including the Beast headers?") +# else +# warning "Have you included your BeastConfig.h file before including the Beast headers?" +# endif +#endif + +#include "../beast_core/beast_core.h" +#include "../beast_basics/beast_basics.h" + +//------------------------------------------------------------------------------ + +namespace beast +{ + +#include "keyvalue/beast_KeyvaDB.h" + +} + +#endif diff --git a/Subtrees/beast/modules/beast_db/beast_db.mm b/Subtrees/beast/modules/beast_db/beast_db.mm new file mode 100644 index 0000000000..2ae0b83c82 --- /dev/null +++ b/Subtrees/beast/modules/beast_db/beast_db.mm @@ -0,0 +1,20 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include "beast_db.cpp" diff --git a/modules/ripple_app/node/ripple_KeyvaDB.cpp b/Subtrees/beast/modules/beast_db/keyvalue/beast_KeyvaDB.cpp similarity index 96% rename from modules/ripple_app/node/ripple_KeyvaDB.cpp rename to Subtrees/beast/modules/beast_db/keyvalue/beast_KeyvaDB.cpp index 8b8e4652dc..7867292d74 100644 --- a/modules/ripple_app/node/ripple_KeyvaDB.cpp +++ b/Subtrees/beast/modules/beast_db/keyvalue/beast_KeyvaDB.cpp @@ -1,8 +1,22 @@ //------------------------------------------------------------------------------ /* - Copyright (c) 2011-2013, OpenCoin, Inc. + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== + /* TODO @@ -110,7 +124,7 @@ public: }; // Key records are indexed starting at one. - struct KeyRecord + struct KeyRecord : Uncopyable { explicit KeyRecord (void* const keyStorage) : key (keyStorage) @@ -139,7 +153,7 @@ public: // are identical to the format on disk. Therefore it is necessary to // use the serialization routines to extract or update the key records. // - class KeyBlock + class KeyBlock : Uncopyable { public: KeyBlock (int depth, int keyBytes) @@ -177,6 +191,7 @@ public: stream.read (keyRecord->key, m_keyBytes); } +#if 0 void writeKeyRecord (KeyRecord const& keyRecord, int keyIndex) { bassert (keyIndex >=1 && keyIndex <= calcKeysAtDepth (m_depth)); @@ -195,6 +210,7 @@ public: stream.write (keyRecord.key, m_keyBytes); #endif } +#endif private: int const m_depth; @@ -459,7 +475,7 @@ public: //-------------------------------------------------------------------------- - struct FindResult + struct FindResult : Uncopyable { FindResult (void* const keyStorage) : keyRecord (keyStorage) diff --git a/Subtrees/beast/modules/beast_db/keyvalue/beast_KeyvaDB.h b/Subtrees/beast/modules/beast_db/keyvalue/beast_KeyvaDB.h new file mode 100644 index 0000000000..20e4185f49 --- /dev/null +++ b/Subtrees/beast/modules/beast_db/keyvalue/beast_KeyvaDB.h @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_KEYVADB_H_INCLUDED +#define BEAST_KEYVADB_H_INCLUDED + +/** Specialized Key/value database + + Once written, a value can never be modified. +*/ +class KeyvaDB : LeakChecked +{ +public: + class GetCallback + { + public: + virtual void* getStorageForValue (int valueBytes) = 0; + }; + + static KeyvaDB* New (int keyBytes, + int keyBlockDepth, + File keyPath, + File valPath); + + virtual ~KeyvaDB () { } + + // VFALCO TODO Make the return value a Result so we can + // detect corruption and errors! + // + virtual bool get (void const* key, GetCallback* callback) = 0; + + // VFALCO TODO Use Result for return value + // + virtual void put (void const* key, void const* value, int valueBytes) = 0; + + virtual void flush () = 0; +}; + +#endif diff --git a/TODO.txt b/TODO.txt index d2e68f7656..69e5eda3da 100644 --- a/TODO.txt +++ b/TODO.txt @@ -4,6 +4,7 @@ RIPPLE TODO Items marked '*' can be handled by third parties. + Vinnie's Short List (Changes day to day) - Make theConfig a SharedSingleton to prevent leak warnings - Add fast backend to the unit test @@ -20,6 +21,8 @@ Vinnie's Short List (Changes day to day) -------------------------------------------------------------------------------- +- Raise the warning level and fix everything + * Restyle all the macros in ripple_ConfigSection.h * Replace all throw with beast::Throw @@ -139,8 +142,6 @@ Vinnie's Short List (Changes day to day) - Make LevelDB and Ripple code work with both Unicode and non-Unicode Windows APIs -- Raise the warning level and fix everything - - Go searching through VFALCO notes and fix everything - Deal with function-level statics used for SqliteDatabase (like in diff --git a/modules/ripple_app/node/ripple_KeyvaDB.h b/modules/ripple_app/node/ripple_KeyvaDB.h deleted file mode 100644 index a58a469829..0000000000 --- a/modules/ripple_app/node/ripple_KeyvaDB.h +++ /dev/null @@ -1,40 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -#ifndef RIPPLE_KEYVADB_H_INCLUDED -#define RIPPLE_KEYVADB_H_INCLUDED - -/** Key/value database optimized for Ripple usage. -*/ -class KeyvaDB : LeakChecked -{ -public: - class GetCallback - { - public: - virtual void* getStorageForValue (int valueBytes) = 0; - }; - - static KeyvaDB* New (int keyBytes, - int keyBlockDepth, - File keyPath, - File valPath); - - virtual ~KeyvaDB () { } - - // VFALCO TODO Make the return value a Result so we can - // detect corruption and errors! - // - virtual bool get (void const* key, GetCallback* callback) = 0; - - // VFALCO TODO Use Result for return value - // - virtual void put (void const* key, void const* value, int valueBytes) = 0; - - virtual void flush () = 0; -}; - -#endif diff --git a/modules/ripple_app/ripple_app.cpp b/modules/ripple_app/ripple_app.cpp index 1d5bb112e0..ae84625c3b 100644 --- a/modules/ripple_app/ripple_app.cpp +++ b/modules/ripple_app/ripple_app.cpp @@ -65,6 +65,8 @@ #include "../ripple_core/ripple_core.h" +#include "beast/modules/beast_db/beast_db.h" + // VFALCO TODO fix these warnings! #ifdef _MSC_VER //#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length" @@ -246,8 +248,6 @@ static const uint64 tenTo17m1 = tenTo17 - 1; #include "node/ripple_NodeObject.cpp" #include "node/ripple_NodeStore.cpp" #include "node/ripple_HyperLevelDBBackendFactory.cpp" -#include "node/ripple_KeyvaDB.h" // private -#include "node/ripple_KeyvaDB.cpp" #include "node/ripple_KeyvaDBBackendFactory.cpp" #include "node/ripple_LevelDBBackendFactory.cpp" #include "node/ripple_NullBackendFactory.cpp"