Skip to content

Commit

Permalink
Deprecate all KV APIs.
Browse files Browse the repository at this point in the history
Closes #1257.
  • Loading branch information
tdenniston committed Jun 25, 2019
1 parent 827fe10 commit fac8e76
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 58 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
* Removed 256-character length limit from URIs.
* Dense reads and writes now always require a subarray to be set, to avoid confusion.

## Deprecations

* The TileDB KV API has been deprecated and will be [removed entirely](https://github.com/TileDB-Inc/TileDB/issues/1258) in a future release. The KV mechanism will be removed when full support for string-valued dimensions has been added.

## Bug fixes

* Bug fix with amplification factor in consolidation.
Expand Down
5 changes: 3 additions & 2 deletions doc/source/tutorials/kv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ to TileDB arrays.

.. warning::

This TileDB feature is experimental. Everything covered here works
great, but the APIs might undergo changes in future versions.
The TileDB key-value API has been deprecated and will be
`removed entirely <https://github.com/TileDB-Inc/TileDB/issues/1258>`_
in a future release.

.. table:: Full programs
:widths: auto
Expand Down
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ if (WIN32)
else()
# Don't treat printf format warnings as errors.
add_compile_options(-Wno-error=format)
# TODO: Remove when KV API has been removed.
add_compile_options(-Wno-deprecated-declarations)
endif()

# The examples pretend as if they use an installed TileDB, e.g.
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ add_executable(
${TILEDB_TEST_SOURCES}
)

# TODO: Remove when KV API has been removed.
if (NOT WIN32)
target_compile_options(tiledb_unit PRIVATE -Wno-deprecated-declarations)
endif()

target_include_directories(
tiledb_unit BEFORE PRIVATE
${TILEDB_CORE_INCLUDE_DIR}
Expand Down
89 changes: 82 additions & 7 deletions tiledb/sm/c_api/tiledb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3501,8 +3501,39 @@ int32_t tiledb_kv_schema_check(

int32_t tiledb_kv_schema_load(
tiledb_ctx_t* ctx, const char* kv_uri, tiledb_kv_schema_t** kv_schema) {
return tiledb_kv_schema_load_with_key(
ctx, kv_uri, TILEDB_NO_ENCRYPTION, nullptr, 0, kv_schema);
if (sanity_check(ctx) == TILEDB_ERR)
return TILEDB_ERR;
// Create array schema
*kv_schema = new (std::nothrow) tiledb_kv_schema_t;
if (*kv_schema == nullptr) {
tiledb::sm::Status st = tiledb::sm::Status::Error(
"Failed to allocate TileDB key-value schema object");
LOG_STATUS(st);
save_error(ctx, st);
return TILEDB_OOM;
}

// Create key
tiledb::sm::EncryptionKey key;
if (SAVE_ERROR_CATCH(
ctx,
key.set_key(tiledb::sm::EncryptionType::NO_ENCRYPTION, nullptr, 0)))
return TILEDB_ERR;

// Load array schema
auto storage_manager = ctx->ctx_->storage_manager();
if (SAVE_ERROR_CATCH(
ctx,
storage_manager->load_array_schema(
tiledb::sm::URI(kv_uri),
tiledb::sm::ObjectType::KEY_VALUE,
key,
&((*kv_schema)->array_schema_)))) {
delete *kv_schema;
return TILEDB_ERR;
}

return TILEDB_OK;
}

int32_t tiledb_kv_schema_load_with_key(
Expand Down Expand Up @@ -3958,8 +3989,36 @@ int32_t tiledb_kv_create(
tiledb_ctx_t* ctx,
const char* kv_uri,
const tiledb_kv_schema_t* kv_schema) {
return tiledb_kv_create_with_key(
ctx, kv_uri, kv_schema, TILEDB_NO_ENCRYPTION, nullptr, 0);
// Sanity checks
if (sanity_check(ctx) == TILEDB_ERR ||
sanity_check(ctx, kv_schema) == TILEDB_ERR)
return TILEDB_ERR;

// Check key-value name
tiledb::sm::URI uri(kv_uri);
if (uri.is_invalid()) {
tiledb::sm::Status st = tiledb::sm::Status::Error(
"Failed to create key-value store; Invalid array URI");
LOG_STATUS(st);
save_error(ctx, st);
return TILEDB_ERR;
}

// Create key
tiledb::sm::EncryptionKey key;
if (SAVE_ERROR_CATCH(
ctx,
key.set_key(tiledb::sm::EncryptionType::NO_ENCRYPTION, nullptr, 0)))
return TILEDB_ERR;

// Create the key-value store
if (SAVE_ERROR_CATCH(
ctx,
ctx->ctx_->storage_manager()->array_create(
uri, kv_schema->array_schema_, key)))
return TILEDB_ERR;

return TILEDB_OK;
}

int32_t tiledb_kv_create_with_key(
Expand Down Expand Up @@ -4006,8 +4065,20 @@ int32_t tiledb_kv_create_with_key(

int32_t tiledb_kv_consolidate(
tiledb_ctx_t* ctx, const char* kv_uri, tiledb_config_t* config) {
return tiledb_kv_consolidate_with_key(
ctx, kv_uri, TILEDB_NO_ENCRYPTION, nullptr, 0, config);
if (sanity_check(ctx) == TILEDB_ERR)
return TILEDB_ERR;

if (SAVE_ERROR_CATCH(
ctx,
ctx->ctx_->storage_manager()->array_consolidate(
kv_uri,
tiledb::sm::EncryptionType::NO_ENCRYPTION,
nullptr,
0,
(config == nullptr) ? nullptr : config->config_)))
return TILEDB_ERR;

return TILEDB_OK;
}

int32_t tiledb_kv_consolidate_with_key(
Expand Down Expand Up @@ -4364,7 +4435,11 @@ int32_t tiledb_kv_iter_here(
}

if (SAVE_ERROR_CATCH(ctx, kv_iter->kv_iter_->here(&((*kv_item)->kv_item_)))) {
tiledb_kv_item_free(kv_item);
if (kv_item != nullptr && *kv_item != nullptr) {
delete (*kv_item)->kv_item_;
delete *kv_item;
*kv_item = nullptr;
}
return TILEDB_ERR;
}

Expand Down
Loading

0 comments on commit fac8e76

Please sign in to comment.