Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting of schema-creation timestamp [WIP] #5260

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/src/unit-capi-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ TEST_CASE(
rc = tiledb_array_get_enumeration(ctx, array, nullptr, &enmr);
REQUIRE(rc == TILEDB_ERR);
}

// XXX TOUCH
2 changes: 2 additions & 0 deletions test/src/unit-cppapi-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,5 @@ void CPPEnumerationFx::rm_array() {
vfs_.remove_dir(uri_);
}
}

// XXX TOUCH
2 changes: 2 additions & 0 deletions test/src/unit-rest-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,5 @@ void RESTEnumerationFx::create_array(const std::string& array_name) {
query.finalize();
array.close();
}

// XXX TOUCH
34 changes: 34 additions & 0 deletions tiledb/api/c_api/array_schema/array_schema_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ capi_return_t tiledb_array_schema_alloc(
return TILEDB_OK;
}

capi_return_t tiledb_array_schema_alloc_at_timestamp(
tiledb_ctx_t* ctx,
tiledb_array_type_t array_type,
uint64_t t1,
uint64_t t2,
tiledb_array_schema_t** array_schema) {
ensure_output_pointer_is_valid(array_schema);

// Create ArraySchema object
auto memory_tracker = ctx->resources().create_memory_tracker();
memory_tracker->set_type(MemoryTrackerType::ARRAY_CREATE);
auto timestamp_range = std::make_pair(t1, t2);
auto opt_range =
std::optional<std::pair<uint64_t, uint64_t>>(timestamp_range);
*array_schema = tiledb_array_schema_t::make_handle(
static_cast<tiledb::sm::ArrayType>(array_type),
memory_tracker,
opt_range);

return TILEDB_OK;
}

void tiledb_array_schema_free(tiledb_array_schema_t** array_schema) {
ensure_output_pointer_is_valid(array_schema);
ensure_array_schema_is_valid(*array_schema);
Expand Down Expand Up @@ -454,6 +476,18 @@ CAPI_INTERFACE(
ctx, array_type, array_schema);
}

CAPI_INTERFACE(
array_schema_alloc_at_timestamp,
tiledb_ctx_t* ctx,
tiledb_array_type_t array_type,
uint64_t t1,
uint64_t t2,
tiledb_array_schema_t** array_schema) {
return api_entry_with_context<
tiledb::api::tiledb_array_schema_alloc_at_timestamp>(
ctx, array_type, t1, t2, array_schema);
}

CAPI_INTERFACE_VOID(array_schema_free, tiledb_array_schema_t** array_schema) {
return api_entry_void<tiledb::api::tiledb_array_schema_free>(array_schema);
}
Expand Down
25 changes: 25 additions & 0 deletions tiledb/api/c_api/array_schema/array_schema_api_external.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,31 @@ TILEDB_EXPORT capi_return_t tiledb_array_schema_alloc(
tiledb_array_type_t array_type,
tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT;

/**
* Creates a TileDB array schema object with specified creation time.
*
* **Example:**
*
* @code{.c}
* tiledb_array_schema_t* array_schema;
* uint64_t t1 = 10;
* uint64_t t2 = 20;
* tiledb_array_schema_alloc_at_timestamp(ctx, TILEDB_DENSE, t1, t2,
* &array_schema);
* @endcode
*
* @param[in] ctx The TileDB context.
* @param[in] array_type The array type.
* @param[out] array_schema The TileDB array schema to be created.
* @return `TILEDB_OK` for success and `TILEDB_OOM` or `TILEDB_ERR` for error.
*/
TILEDB_EXPORT capi_return_t tiledb_array_schema_alloc_at_timestamp(
tiledb_ctx_t* ctx,
tiledb_array_type_t array_type,
uint64_t t1,
uint64_t t2,
tiledb_array_schema_t** array_schema) TILEDB_NOEXCEPT;

/**
* Destroys an array schema, freeing associated memory.
*
Expand Down
2 changes: 2 additions & 0 deletions tiledb/api/c_api/enumeration/test/unit_capi_enumeration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,5 @@ TEST_CASE(
REQUIRE(rc == TILEDB_ERR);
}
}

// XXX TOUCH
2 changes: 1 addition & 1 deletion tiledb/sm/array/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void Array::create(

std::lock_guard<std::mutex> lock{object_mtx};
array_schema->set_array_uri(array_uri);
array_schema->generate_uri();
array_schema->generate_uri(array_schema->timestamp_range());
array_schema->check(resources.config());

// Check current domain is specified correctly if set
Expand Down
15 changes: 11 additions & 4 deletions tiledb/sm/array_schema/array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,20 @@ class ArraySchemaException : public StatusException {
/* ****************************** */

ArraySchema::ArraySchema(
ArrayType array_type, shared_ptr<MemoryTracker> memory_tracker)
ArrayType array_type,
shared_ptr<MemoryTracker> memory_tracker,
std::optional<std::pair<uint64_t, uint64_t>> timestamp_range)
: memory_tracker_(memory_tracker)
, uri_(URI())
, array_uri_(URI())
, version_(constants::format_version)
, timestamp_range_(std::make_pair(
utils::time::timestamp_now_ms(), utils::time::timestamp_now_ms()))
, timestamp_range_(
timestamp_range.has_value() ? std::make_pair(
timestamp_range.value().first,
timestamp_range.value().second) :
std::make_pair(
utils::time::timestamp_now_ms(),
utils::time::timestamp_now_ms()))
, name_("")
, array_type_(array_type)
, allows_dups_(false)
Expand Down Expand Up @@ -121,7 +128,7 @@ ArraySchema::ArraySchema(
Datatype::UINT8));

// Generate URI and name for ArraySchema
generate_uri();
generate_uri(timestamp_range);
}

ArraySchema::ArraySchema(
Expand Down
6 changes: 5 additions & 1 deletion tiledb/sm/array_schema/array_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ class ArraySchema {
* @param memory_tracker The memory tracker of the array this fragment
* metadata corresponds to.
*/
ArraySchema(ArrayType array_type, shared_ptr<MemoryTracker> memory_tracker);
ArraySchema(
ArrayType array_type,
shared_ptr<MemoryTracker> memory_tracker,
std::optional<std::pair<uint64_t, uint64_t>> timestamp_range =
std::nullopt);

/** Constructor with std::vector attributes.
* @param uri The URI of the array schema file.
Expand Down
17 changes: 15 additions & 2 deletions tiledb/sm/cpp_api/array_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,23 @@ class ArraySchema : public Schema {
* @param ctx TileDB context
* @param type Array type, sparse or dense.
*/
explicit ArraySchema(const Context& ctx, tiledb_array_type_t type)
explicit ArraySchema(
const Context& ctx,
tiledb_array_type_t type,
std::optional<std::pair<int64_t, int64_t>> timestamp_range = std::nullopt)
: Schema(ctx) {
tiledb_array_schema_t* schema;
ctx.handle_error(tiledb_array_schema_alloc(ctx.ptr().get(), type, &schema));
if (timestamp_range.has_value()) {
ctx.handle_error(tiledb_array_schema_alloc_at_timestamp(
ctx.ptr().get(),
type,
timestamp_range.value().first,
timestamp_range.value().second,
&schema));
} else {
ctx.handle_error(
tiledb_array_schema_alloc(ctx.ptr().get(), type, &schema));
}
schema_ = std::shared_ptr<tiledb_array_schema_t>(schema, deleter_);
}

Expand Down