diff options
author | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-12-12 11:58:40 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-12-15 15:20:07 +0000 |
commit | a248ff694ca95218c4127f9156735ceb3fbba4d7 (patch) | |
tree | 2310e595b1e280c30b33a17d77dd13b7396a48cf /persistence/src | |
parent | 77242dcd5594b4b481403491c47979cc866a569c (diff) |
Add configurable bucket resolver and fixed space repo
Make default (aka. placeholder) bucket space index 1, not 0.
Bucket space index 0 is now considered an invalid space.
Diffstat (limited to 'persistence/src')
5 files changed, 135 insertions, 6 deletions
diff --git a/persistence/src/tests/spi/CMakeLists.txt b/persistence/src/tests/spi/CMakeLists.txt index a130573e028..c51270a420c 100644 --- a/persistence/src/tests/spi/CMakeLists.txt +++ b/persistence/src/tests/spi/CMakeLists.txt @@ -2,6 +2,7 @@ vespa_add_library(persistence_testspi SOURCES clusterstatetest.cpp + fixed_bucket_spaces_test.cpp DEPENDS persistence_persistence_conformancetest persistence diff --git a/persistence/src/tests/spi/fixed_bucket_spaces_test.cpp b/persistence/src/tests/spi/fixed_bucket_spaces_test.cpp new file mode 100644 index 00000000000..7e36d80248a --- /dev/null +++ b/persistence/src/tests/spi/fixed_bucket_spaces_test.cpp @@ -0,0 +1,64 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/persistence/spi/fixed_bucket_spaces.h> +#include <cppunit/extensions/HelperMacros.h> + +namespace storage::spi { + +struct FixedBucketSpacesTest : CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(FixedBucketSpacesTest); + CPPUNIT_TEST(bucket_space_from_name_is_defined_for_default_space); + CPPUNIT_TEST(bucket_space_from_name_is_defined_for_global_space); + CPPUNIT_TEST(bucket_space_from_name_throws_exception_for_unknown_space); + CPPUNIT_TEST(name_from_bucket_space_is_defined_for_default_space); + CPPUNIT_TEST(name_from_bucket_space_is_defined_for_global_space); + CPPUNIT_TEST(name_from_bucket_space_throws_exception_for_unknown_space); + CPPUNIT_TEST_SUITE_END(); + + void bucket_space_from_name_is_defined_for_default_space(); + void bucket_space_from_name_is_defined_for_global_space(); + void bucket_space_from_name_throws_exception_for_unknown_space(); + void name_from_bucket_space_is_defined_for_default_space(); + void name_from_bucket_space_is_defined_for_global_space(); + void name_from_bucket_space_throws_exception_for_unknown_space(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(FixedBucketSpacesTest); + +using document::BucketSpace; + +void FixedBucketSpacesTest::bucket_space_from_name_is_defined_for_default_space() { + CPPUNIT_ASSERT_EQUAL(FixedBucketSpaces::default_space(), FixedBucketSpaces::from_string("default")); +} + +void FixedBucketSpacesTest::bucket_space_from_name_is_defined_for_global_space() { + CPPUNIT_ASSERT_EQUAL(FixedBucketSpaces::global_space(), FixedBucketSpaces::from_string("global")); +} + +void FixedBucketSpacesTest::bucket_space_from_name_throws_exception_for_unknown_space() { + try { + FixedBucketSpaces::from_string("banana"); + CPPUNIT_FAIL("Expected exception on unknown bucket space name"); + } catch (spi::UnknownBucketSpaceException& e) { + } +} + +void FixedBucketSpacesTest::name_from_bucket_space_is_defined_for_default_space() { + CPPUNIT_ASSERT_EQUAL(vespalib::stringref("default"), + FixedBucketSpaces::to_string(FixedBucketSpaces::default_space())); +} + +void FixedBucketSpacesTest::name_from_bucket_space_is_defined_for_global_space() { + CPPUNIT_ASSERT_EQUAL(vespalib::stringref("global"), + FixedBucketSpaces::to_string(FixedBucketSpaces::global_space())); +} + +void FixedBucketSpacesTest::name_from_bucket_space_throws_exception_for_unknown_space() { + try { + FixedBucketSpaces::to_string(BucketSpace(4567)); + CPPUNIT_FAIL("Expected exception on unknown bucket space value"); + } catch (spi::UnknownBucketSpaceException& e) { + } +} + +}
\ No newline at end of file diff --git a/persistence/src/vespa/persistence/spi/CMakeLists.txt b/persistence/src/vespa/persistence/spi/CMakeLists.txt index a8b1faadcd3..a2b8fa7a79c 100644 --- a/persistence/src/vespa/persistence/spi/CMakeLists.txt +++ b/persistence/src/vespa/persistence/spi/CMakeLists.txt @@ -1,19 +1,20 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(persistence_spi OBJECT SOURCES + abstractpersistenceprovider.cpp bucket.cpp bucketinfo.cpp - exceptions.cpp - persistenceprovider.cpp - partitionstate.cpp - abstractpersistenceprovider.cpp clusterstate.cpp context.cpp + docentry.cpp + exceptions.cpp + fixed_bucket_spaces.cpp metricpersistenceprovider.cpp + partitionstate.cpp + persistenceprovider.cpp read_consistency.cpp - result + result.cpp selection.cpp test.cpp - docentry DEPENDS ) diff --git a/persistence/src/vespa/persistence/spi/fixed_bucket_spaces.cpp b/persistence/src/vespa/persistence/spi/fixed_bucket_spaces.cpp new file mode 100644 index 00000000000..6a8ec0f18f7 --- /dev/null +++ b/persistence/src/vespa/persistence/spi/fixed_bucket_spaces.cpp @@ -0,0 +1,33 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "fixed_bucket_spaces.h" + +namespace storage::spi { + +VESPA_IMPLEMENT_EXCEPTION(UnknownBucketSpaceException, vespalib::IllegalArgumentException) + +// Some sanity checks to ensure we don't mess up any legacy mappings. +static_assert(document::BucketSpace::placeHolder() != document::BucketSpace::invalid()); +static_assert(FixedBucketSpaces::default_space() == document::BucketSpace::placeHolder()); +static_assert(FixedBucketSpaces::global_space() != FixedBucketSpaces::default_space()); + +document::BucketSpace FixedBucketSpaces::from_string(vespalib::stringref name) { + if (name == "default") { + return default_space(); + } else if (name == "global") { + return global_space(); + } else { + throw UnknownBucketSpaceException("Unknown bucket space name: " + vespalib::string(name), VESPA_STRLOC); + } +} + +vespalib::stringref FixedBucketSpaces::to_string(document::BucketSpace space) { + if (space == default_space()) { + return "default"; + } else if (space == global_space()) { + return "global"; + } else { + throw UnknownBucketSpaceException("Unknown bucket space: " + space.toString(), VESPA_STRLOC); + } +} + +} diff --git a/persistence/src/vespa/persistence/spi/fixed_bucket_spaces.h b/persistence/src/vespa/persistence/spi/fixed_bucket_spaces.h new file mode 100644 index 00000000000..c2e97407797 --- /dev/null +++ b/persistence/src/vespa/persistence/spi/fixed_bucket_spaces.h @@ -0,0 +1,30 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <vespa/document/bucket/bucketspace.h> +#include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/stllike/string.h> + +namespace storage::spi { + +VESPA_DEFINE_EXCEPTION(UnknownBucketSpaceException, vespalib::IllegalArgumentException); + +/** + * Minimal repository/factory of bucket spaces hard coded for default and global + * distributions. + */ +struct FixedBucketSpaces { + static constexpr document::BucketSpace default_space() { return document::BucketSpace(1); }; + static constexpr document::BucketSpace global_space() { return document::BucketSpace(2); } + + // Post-condition: returned space has valid() == true iff name + // is either "default" or "global". + // Throws UnknownBucketSpaceException if name does not map to a known bucket space. + static document::BucketSpace from_string(vespalib::stringref name); + // Post-condition: returned string can be losslessly passed to from_string() + // iff space is equal to default_space() or global_space(). + // Throws UnknownBucketSpaceException if space does not map to a known name. + static vespalib::stringref to_string(document::BucketSpace space); +}; + +} |