Skip to content
Snippets Groups Projects
Commit 0bfe511d authored by Dmitry Simonenko's avatar Dmitry Simonenko
Browse files

sophia-update: changes to support v1.2

parent 3e3bce76
No related branches found
No related tags found
No related merge requests found
...@@ -316,7 +316,7 @@ add_dependencies(build_bundled_libs misc) ...@@ -316,7 +316,7 @@ add_dependencies(build_bundled_libs misc)
include(BuildSophia) include(BuildSophia)
sophia_build() sophia_build()
set (sophia_lib "${PROJECT_BINARY_DIR}/third_party/sophia/db/libsophia.a") set (sophia_lib "${PROJECT_BINARY_DIR}/third_party/sophia/env/libsophia.a")
option(ENABLE_RPM "Enable install of a RPM specific files" OFF) option(ENABLE_RPM "Enable install of a RPM specific files" OFF)
......
# A macro to build the bundled sophia library # A macro to build the bundled sophia library
# #
macro(sophia_build) macro(sophia_build)
set(SOPHIA_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/third_party/sophia/db) set(SOPHIA_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/third_party/sophia/env)
if (${PROJECT_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) if (${PROJECT_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/third_party/sophia/db/libsophia.a add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/third_party/sophia/env/libsophia.a
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/sophia WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/sophia
COMMAND $(MAKE) -C db libsophia.a COMMAND $(MAKE)
DEPENDS ${CMAKE_SOURCE_DIR}/CMakeCache.txt DEPENDS ${CMAKE_SOURCE_DIR}/CMakeCache.txt
) )
else() else()
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/third_party/sophia add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/third_party/sophia
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/third_party/sophia COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/third_party/sophia
) )
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/third_party/sophia/db/libsophia.a add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/third_party/sophia/env/libsophia.a
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/third_party/sophia WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/third_party/sophia
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/third_party/sophia ${PROJECT_BINARY_DIR}/third_party/sophia COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/third_party/sophia ${PROJECT_BINARY_DIR}/third_party/sophia
COMMAND $(MAKE) -C db libsophia.a COMMAND $(MAKE)
DEPENDS ${PROJECT_BINARY_DIR}/CMakeCache.txt ${PROJECT_BINARY_DIR}/third_party/sophia DEPENDS ${PROJECT_BINARY_DIR}/CMakeCache.txt ${PROJECT_BINARY_DIR}/third_party/sophia
) )
endif() endif()
add_custom_target(libsophia ALL add_custom_target(libsophia ALL
DEPENDS ${PROJECT_BINARY_DIR}/third_party/sophia/db/libsophia.a DEPENDS ${PROJECT_BINARY_DIR}/third_party/sophia/env/libsophia.a
) )
message(STATUS "Use bundled sophia: ${SOPHIA_INCLUDE_DIR}") message(STATUS "Use bundled sophia: ${SOPHIA_INCLUDE_DIR}")
......
...@@ -94,12 +94,16 @@ SophiaFactory::SophiaFactory() ...@@ -94,12 +94,16 @@ SophiaFactory::SophiaFactory()
void void
SophiaFactory::init() SophiaFactory::init()
{ {
int rc = mkdir("sophia", 0755); env = sp_env();
if (env == NULL)
if (rc == -1 && errno != EEXIST) { panic("failed to create sophia environment");
say_error("failed to create directory: 'sophia', %d, %s", void *conf = sp_use(env, "conf");
errno, strerror(errno)); sp_set(conf, "env.logdir", "sophia_wal");
} sp_set(conf, "env.dir", "sophia");
sp_destroy(conf);
int rc = sp_open(env);
if (rc == -1)
panic("sophia recovery failed");
} }
Engine* Engine*
......
...@@ -38,6 +38,7 @@ struct SophiaFactory: public EngineFactory { ...@@ -38,6 +38,7 @@ struct SophiaFactory: public EngineFactory {
virtual void keydefCheck(struct key_def *key_def); virtual void keydefCheck(struct key_def *key_def);
virtual void txnFinish(struct txn *txn); virtual void txnFinish(struct txn *txn);
virtual void recoveryEvent(enum engine_recovery_event event); virtual void recoveryEvent(enum engine_recovery_event event);
void *env;
}; };
#endif /* TARANTOOL_BOX_ENGINE_SOPHIA_H_INCLUDED */ #endif /* TARANTOOL_BOX_ENGINE_SOPHIA_H_INCLUDED */
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "schema.h" #include "schema.h"
#include "space.h" #include "space.h"
#include "engine_sophia.h"
#include <sophia.h> #include <sophia.h>
#include <stdio.h> #include <stdio.h>
...@@ -73,33 +74,28 @@ sophia_gettuple(void *db, const char *key, size_t keysize) ...@@ -73,33 +74,28 @@ sophia_gettuple(void *db, const char *key, size_t keysize)
SophiaIndex::SophiaIndex(struct key_def *key_def_arg __attribute__((unused))) SophiaIndex::SophiaIndex(struct key_def *key_def_arg __attribute__((unused)))
: Index(key_def_arg) : Index(key_def_arg)
{ {
env = sp_env(); struct space *space = space_cache_find(key_def->space_id);
if (env == NULL) SophiaFactory *factory =
tnt_raise(ClientError, ER_MEMORY_ISSUE, sizeof(void*), (SophiaFactory*)space->engine->factory;
"SophiaIndex", "env"); env = factory->env;
auto env_freer = db = sp_use(env, space->def.name);
make_scoped_guard([=] { sp_destroy(env); }); if (db == NULL) {
void *cmp = sp_use(env, "cmp");
int rc = sp_ctl(env, SPCMP, sophia_index_compare, key_def); sp_set(cmp, "tarantool_cmp", sophia_index_compare, key_def);
if (rc == -1) sp_destroy(cmp);
tnt_raise(ClientError, ER_SOPHIA, sp_error(env)); char name[64];
snprintf(name, sizeof(name), "%s.cmp", space->def.name);
char path[PATH_MAX]; void *scheme = sp_use(env, "scheme");
snprintf(path, sizeof(path), "sophia/%04d", key_def->space_id); void *stx = sp_begin(scheme);
rc = sp_ctl(env, SPDIR, SPO_RDWR|SPO_CREAT, path); sp_set(stx, name, "tarantool_cmp");
if (rc == -1) int rc = sp_commit(stx);
tnt_raise(ClientError, ER_SOPHIA, sp_error(env)); sp_destroy(scheme);
if (rc == -1)
say_info("start sophia space '%s' recover", path); tnt_raise(ClientError, ER_SOPHIA, sp_error(env));
db = sp_use(env, space->def.name);
db = sp_open(env); assert(db != NULL);
if (db == NULL) }
tnt_raise(ClientError, ER_SOPHIA, sp_error(env));
say_info("recover complete");
env_freer.is_active = false;
} }
SophiaIndex::~SophiaIndex() SophiaIndex::~SophiaIndex()
...@@ -108,16 +104,12 @@ SophiaIndex::~SophiaIndex() ...@@ -108,16 +104,12 @@ SophiaIndex::~SophiaIndex()
m_position->free(m_position); m_position->free(m_position);
m_position = NULL; m_position = NULL;
} }
if (db) { if (db) {
int rc = sp_destroy(db); int rc = sp_destroy(db);
if (rc == -1) if (rc == -1)
say_info("sophia space %d close error: %s", key_def->space_id, say_info("sophia space %d close error: %s", key_def->space_id,
sp_error(env)); sp_error(env));
} }
if (env) {
sp_destroy(env);
}
} }
void void
...@@ -268,7 +260,7 @@ sophia_iterator_next(struct iterator *ptr) ...@@ -268,7 +260,7 @@ sophia_iterator_next(struct iterator *ptr)
if (rc == 0) if (rc == 0)
return NULL; return NULL;
size_t valuesize = sp_valuesize(it->cursor); size_t valuesize = sp_valuesize(it->cursor);
const char *value = sp_value(it->cursor); const char *value = (const char*)sp_value(it->cursor);
struct tuple *ret = struct tuple *ret =
tuple_new(tuple_format_ber, value, value + valuesize); tuple_new(tuple_format_ber, value, value + valuesize);
tuple_ref(ret, 1); tuple_ref(ret, 1);
...@@ -329,19 +321,18 @@ SophiaIndex::initIterator(struct iterator *ptr, enum iterator_type type, ...@@ -329,19 +321,18 @@ SophiaIndex::initIterator(struct iterator *ptr, enum iterator_type type,
it->keysize = keysize; it->keysize = keysize;
it->part_count = part_count; it->part_count = part_count;
it->db = db; it->db = db;
const char *compare;
sporder compare;
switch (type) { switch (type) {
case ITER_EQ: it->base.next = sophia_iterator_eq; case ITER_EQ: it->base.next = sophia_iterator_eq;
return; return;
case ITER_ALL: case ITER_ALL:
case ITER_GE: compare = SPGTE; case ITER_GE: compare = ">=";
break; break;
case ITER_GT: compare = SPGT; case ITER_GT: compare = ">";
break; break;
case ITER_LE: compare = SPLTE; case ITER_LE: compare = "<=";
break; break;
case ITER_LT: compare = SPLT; case ITER_LT: compare = "<";
break; break;
default: default:
tnt_raise(ClientError, ER_UNSUPPORTED, tnt_raise(ClientError, ER_UNSUPPORTED,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment