diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-05-18 06:19:10 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-05-18 06:36:12 +0000 |
commit | d0d1bd1090e5dcd778eb86ee1c1b1714fd633cae (patch) | |
tree | ca9f4535c4c4c1afe7ab3f85749c691581745354 /persistence | |
parent | fc9c0dcbbff209d47ea1b04f86f36f2ccb0c0ad2 (diff) |
Collapse persistencetypes into persistence
Diffstat (limited to 'persistence')
-rw-r--r-- | persistence/CMakeLists.txt | 1 | ||||
-rw-r--r-- | persistence/src/vespa/persistence/spi/CMakeLists.txt | 1 | ||||
-rw-r--r-- | persistence/src/vespa/persistence/spi/types.cpp | 12 | ||||
-rw-r--r-- | persistence/src/vespa/persistence/spi/types.h | 108 |
4 files changed, 121 insertions, 1 deletions
diff --git a/persistence/CMakeLists.txt b/persistence/CMakeLists.txt index cf94ba3bb52..d87f172bfb5 100644 --- a/persistence/CMakeLists.txt +++ b/persistence/CMakeLists.txt @@ -5,7 +5,6 @@ vespa_define_module( vespalog vespalib document - persistencetypes vdslib LIBS diff --git a/persistence/src/vespa/persistence/spi/CMakeLists.txt b/persistence/src/vespa/persistence/spi/CMakeLists.txt index eda3ffb228f..e4bae1c7551 100644 --- a/persistence/src/vespa/persistence/spi/CMakeLists.txt +++ b/persistence/src/vespa/persistence/spi/CMakeLists.txt @@ -17,5 +17,6 @@ vespa_add_library(persistence_spi OBJECT result.cpp selection.cpp test.cpp + types.cpp DEPENDS ) diff --git a/persistence/src/vespa/persistence/spi/types.cpp b/persistence/src/vespa/persistence/spi/types.cpp new file mode 100644 index 00000000000..260355213d9 --- /dev/null +++ b/persistence/src/vespa/persistence/spi/types.cpp @@ -0,0 +1,12 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "types.h" +#include <vespa/vespalib/objects/nbostream.h> + +namespace storage::spi { + +DEFINE_PRIMITIVE_WRAPPER_NBOSTREAM(NodeIndex); +DEFINE_PRIMITIVE_WRAPPER_NBOSTREAM(IteratorId); +DEFINE_PRIMITIVE_WRAPPER_NBOSTREAM(Timestamp); +DEFINE_PRIMITIVE_WRAPPER_NBOSTREAM(BucketChecksum); + +} diff --git a/persistence/src/vespa/persistence/spi/types.h b/persistence/src/vespa/persistence/spi/types.h new file mode 100644 index 00000000000..a75b977c14a --- /dev/null +++ b/persistence/src/vespa/persistence/spi/types.h @@ -0,0 +1,108 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <vespa/vespalib/stllike/string.h> +#include <vector> +#include <memory> + +namespace vespalib { + class nbostream; +} + +namespace document { + class GlobalId; + class Document; + class DocumentId; + class DocumentUpdate; +} + +/** + * We create small wrapper classes for number values for the following reasons: + * - Being able to create functions taking in several of them, without risking + * caller using numbers in wrong order. + * - We can identify type by typename instead of variable name. + */ +#define DEFINE_PRIMITIVE_WRAPPER(type, name) \ + class name { \ + type _value; \ + public: \ + typedef type Type; \ + name() noexcept : _value() {} \ + explicit name(type v) noexcept : _value(v) {} \ + operator type() const noexcept { return _value; } \ + operator type&() noexcept { return _value; } \ + type getValue() const noexcept { return _value; } \ + name& operator=(type val) noexcept { _value = val; return *this; } \ + friend vespalib::nbostream & \ + operator<<(vespalib::nbostream &os, const name &wrapped); \ + friend vespalib::nbostream & \ + operator>>(vespalib::nbostream &is, name &wrapped); \ + }; \ + +#define DEFINE_PRIMITIVE_WRAPPER_NBOSTREAM(name) \ + vespalib::nbostream & \ + operator<<(vespalib::nbostream &os, const name &wrapped) \ + { \ + os << wrapped._value; \ + return os; \ + } \ + \ + vespalib::nbostream & \ + operator>>(vespalib::nbostream &is, name &wrapped) \ + { \ + is >> wrapped._value; \ + return is; \ + } \ + +namespace storage::spi { + +/** + * \class storage::spi::NodeIndex + * \ingroup spi + */ +DEFINE_PRIMITIVE_WRAPPER(uint16_t, NodeIndex); + +/** + * \class storage::spi::IteratorId + * \ingroup spi + */ +DEFINE_PRIMITIVE_WRAPPER(uint64_t, IteratorId); + +/** + * \class storage::spi::Timestamp + * \ingroup spi + */ +DEFINE_PRIMITIVE_WRAPPER(uint64_t, Timestamp); + +/** + * \class storage::spi::BucketChecksum + * \ingroup spi + */ +DEFINE_PRIMITIVE_WRAPPER(uint32_t, BucketChecksum); + +// Import critical dependencies into SPI namespace. This makes interface look +// cleaner, and makes it easy to exchange actual implementation. +using Document = document::Document; +using DocumentUpdate = document::DocumentUpdate; +using DocumentId = document::DocumentId; +using GlobalId = document::GlobalId; +using TimestampList = std::vector<Timestamp>; +using string = vespalib::string; +using DocumentUP = std::unique_ptr<document::Document>; +using DocumentIdUP = std::unique_ptr<document::DocumentId>; +using DocumentSP = std::shared_ptr<document::Document>; +using DocumentUpdateSP = std::shared_ptr<document::DocumentUpdate>; + +enum IncludedVersions { + NEWEST_DOCUMENT_ONLY, + NEWEST_DOCUMENT_OR_REMOVE, + ALL_VERSIONS +}; + +enum MaintenanceLevel { + LOW, + HIGH +}; + +} |