mirror of
https://github.com/scylladb/scylladb.git
synced 2026-06-02 13:06:57 +00:00
Schema related files are moved there. This excludes schema files that also interact with mutations, because the mutation module depends on the schema. Those files will have to go into a separate module. Closes #12858
144 lines
4.5 KiB
C++
144 lines
4.5 KiB
C++
/*
|
|
* Copyright (C) 2016-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
|
|
#include <seastar/core/thread.hh>
|
|
|
|
#include "test/lib/scylla_test_case.hh"
|
|
#include <seastar/testing/thread_test_case.hh>
|
|
#include "data_dictionary/user_types_metadata.hh"
|
|
#include "schema/schema_registry.hh"
|
|
#include "schema/schema_builder.hh"
|
|
#include "test/lib/mutation_source_test.hh"
|
|
#include "db/config.hh"
|
|
#include "db/schema_tables.hh"
|
|
#include "types/list.hh"
|
|
|
|
static bytes random_column_name() {
|
|
return to_bytes(to_hex(make_blob(32)));
|
|
}
|
|
|
|
static schema_ptr random_schema() {
|
|
return schema_builder("ks", "cf")
|
|
.with_column("pk", bytes_type, column_kind::partition_key)
|
|
.with_column(random_column_name(), bytes_type)
|
|
.build();
|
|
}
|
|
|
|
struct dummy_init {
|
|
std::unique_ptr<db::config> config;
|
|
|
|
dummy_init() {
|
|
config = std::make_unique<db::config>();
|
|
local_schema_registry().init(db::schema_ctxt(*config,std::make_shared<data_dictionary::dummy_user_types_storage>()));
|
|
}
|
|
};
|
|
|
|
SEASTAR_THREAD_TEST_CASE(test_load_with_non_nantive_type) {
|
|
dummy_init dummy;
|
|
auto my_list_type = list_type_impl::get_instance(utf8_type, true);
|
|
|
|
auto s = schema_builder("ks", "cf")
|
|
.with_column("pk", bytes_type, column_kind::partition_key)
|
|
.with_column("val", my_list_type)
|
|
.build();
|
|
|
|
local_schema_registry().get_or_load(s->version(), [s] (table_schema_version) {
|
|
return make_ready_future<frozen_schema>(frozen_schema(s));
|
|
}).get();
|
|
}
|
|
|
|
SEASTAR_TEST_CASE(test_async_loading) {
|
|
return seastar::async([] {
|
|
dummy_init dummy;
|
|
auto s1 = random_schema();
|
|
auto s2 = random_schema();
|
|
|
|
auto s1_loaded = local_schema_registry().get_or_load(s1->version(), [s1] (table_schema_version) {
|
|
return make_ready_future<frozen_schema>(frozen_schema(s1));
|
|
}).get0();
|
|
|
|
BOOST_REQUIRE(s1_loaded);
|
|
BOOST_REQUIRE(s1_loaded->version() == s1->version());
|
|
auto s1_later = local_schema_registry().get_or_null(s1->version());
|
|
BOOST_REQUIRE(s1_later);
|
|
|
|
auto s2_loaded = local_schema_registry().get_or_load(s2->version(), [s2] (table_schema_version) {
|
|
return yield().then([s2] { return frozen_schema(s2); });
|
|
}).get0();
|
|
|
|
BOOST_REQUIRE(s2_loaded);
|
|
BOOST_REQUIRE(s2_loaded->version() == s2->version());
|
|
auto s2_later = local_schema_registry().get_or_null(s2_loaded->version());
|
|
BOOST_REQUIRE(s2_later);
|
|
});
|
|
}
|
|
|
|
SEASTAR_TEST_CASE(test_schema_is_synced_when_syncer_doesnt_defer) {
|
|
return seastar::async([] {
|
|
dummy_init dummy;
|
|
auto s = random_schema();
|
|
s = local_schema_registry().get_or_load(s->version(), [s] (table_schema_version) { return frozen_schema(s); });
|
|
BOOST_REQUIRE(!s->is_synced());
|
|
s->registry_entry()->maybe_sync([] { return make_ready_future<>(); }).get();
|
|
BOOST_REQUIRE(s->is_synced());
|
|
});
|
|
}
|
|
|
|
SEASTAR_TEST_CASE(test_schema_is_synced_when_syncer_defers) {
|
|
return seastar::async([] {
|
|
dummy_init dummy;
|
|
auto s = random_schema();
|
|
s = local_schema_registry().get_or_load(s->version(), [s] (table_schema_version) { return frozen_schema(s); });
|
|
BOOST_REQUIRE(!s->is_synced());
|
|
s->registry_entry()->maybe_sync([] { return yield(); }).get();
|
|
BOOST_REQUIRE(s->is_synced());
|
|
});
|
|
}
|
|
|
|
SEASTAR_TEST_CASE(test_failed_sync_can_be_retried) {
|
|
return seastar::async([] {
|
|
dummy_init dummy;
|
|
auto s = random_schema();
|
|
s = local_schema_registry().get_or_load(s->version(), [s] (table_schema_version) { return frozen_schema(s); });
|
|
BOOST_REQUIRE(!s->is_synced());
|
|
|
|
promise<> fail_sync;
|
|
|
|
auto f1 = s->registry_entry()->maybe_sync([&fail_sync] () mutable {
|
|
return fail_sync.get_future().then([] {
|
|
throw std::runtime_error("sync failed");
|
|
});
|
|
});
|
|
|
|
// concurrent maybe_sync should attach the the current one
|
|
auto f2 = s->registry_entry()->maybe_sync([] { return make_ready_future<>(); });
|
|
|
|
fail_sync.set_value();
|
|
|
|
try {
|
|
f1.get();
|
|
BOOST_FAIL("Should have failed");
|
|
} catch (...) {
|
|
// expected
|
|
}
|
|
|
|
try {
|
|
f2.get();
|
|
BOOST_FAIL("Should have failed");
|
|
} catch (...) {
|
|
// expected
|
|
}
|
|
|
|
BOOST_REQUIRE(!s->is_synced());
|
|
|
|
s->registry_entry()->maybe_sync([] { return make_ready_future<>(); }).get();
|
|
BOOST_REQUIRE(s->is_synced());
|
|
});
|
|
}
|