1
0
Fork 0

Entirely removed TRI_json_t from server.cpp

This commit is contained in:
Michael Hackstein 2016-01-13 10:47:55 +01:00
parent 69f4f974d3
commit 848f807499
1 changed files with 26 additions and 35 deletions

View File

@ -420,10 +420,6 @@ static int OpenDatabases(TRI_server_t* server, regex_t* regex, bool isUpgrade) {
for (auto const& name : files) { for (auto const& name : files) {
TRI_vocbase_t* vocbase; TRI_vocbase_t* vocbase;
TRI_json_t* json;
TRI_json_t const* deletedJson;
TRI_json_t const* nameJson;
TRI_json_t const* idJson;
TRI_voc_tick_t id; TRI_voc_tick_t id;
TRI_vocbase_defaults_t defaults; TRI_vocbase_defaults_t defaults;
char* parametersFile; char* parametersFile;
@ -514,10 +510,12 @@ static int OpenDatabases(TRI_server_t* server, regex_t* regex, bool isUpgrade) {
} }
LOG_DEBUG("reading database parameters from file '%s'", parametersFile); LOG_DEBUG("reading database parameters from file '%s'", parametersFile);
std::string fileName(parametersFile);
json = TRI_JsonFile(TRI_CORE_MEM_ZONE, parametersFile, nullptr); std::shared_ptr<VPackBuilder> builder;
try {
if (json == nullptr) { builder =
triagens::basics::VelocyPackHelper::velocyPackFromFile(fileName);
} catch (...) {
LOG_ERROR( LOG_ERROR(
"database directory '%s' does not contain a valid parameters file", "database directory '%s' does not contain a valid parameters file",
databaseDirectory); databaseDirectory);
@ -528,61 +526,55 @@ static int OpenDatabases(TRI_server_t* server, regex_t* regex, bool isUpgrade) {
res = TRI_ERROR_ARANGO_ILLEGAL_PARAMETER_FILE; res = TRI_ERROR_ARANGO_ILLEGAL_PARAMETER_FILE;
break; break;
} }
VPackSlice parameters = builder->slice();
std::string parametersString = parameters.toJson();
LOG_DEBUG("database parameters: %s", LOG_DEBUG("database parameters: %s", parametersString.c_str());
triagens::basics::JsonHelper::toString(json).c_str());
TRI_FreeString(TRI_CORE_MEM_ZONE, parametersFile); TRI_FreeString(TRI_CORE_MEM_ZONE, parametersFile);
deletedJson = TRI_LookupObjectJson(json, "deleted"); if (triagens::basics::VelocyPackHelper::getBooleanValue(parameters,
"deleted", false)) {
// database is deleted, skip it!
LOG_INFO("found dropped database in directory '%s'", databaseDirectory);
if (TRI_IsBooleanJson(deletedJson)) { LOG_INFO("removing superfluous database directory '%s'",
if (deletedJson->_value._boolean) { databaseDirectory);
// database is deleted, skip it!
LOG_INFO("found dropped database in directory '%s'", databaseDirectory);
LOG_INFO("removing superfluous database directory '%s'", TRI_RemoveDirectory(databaseDirectory);
databaseDirectory);
TRI_RemoveDirectory(databaseDirectory); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory);
continue;
TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory);
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
continue;
}
} }
VPackSlice idSlice = parameters.get("id");
idJson = TRI_LookupObjectJson(json, "id"); if (!idSlice.isString()) {
if (!TRI_IsStringJson(idJson)) {
LOG_ERROR( LOG_ERROR(
"database directory '%s' does not contain a valid parameters file", "database directory '%s' does not contain a valid parameters file",
databaseDirectory); databaseDirectory);
TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory);
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
res = TRI_ERROR_ARANGO_ILLEGAL_PARAMETER_FILE; res = TRI_ERROR_ARANGO_ILLEGAL_PARAMETER_FILE;
break; break;
} }
std::string idString = idSlice.copyString();
id = (TRI_voc_tick_t)TRI_UInt64String(idJson->_value._string.data); id = (TRI_voc_tick_t)TRI_UInt64String(idString.c_str());
nameJson = TRI_LookupObjectJson(json, "name"); VPackSlice nameSlice = parameters.get("name");
if (!TRI_IsStringJson(nameJson)) { if (!nameSlice.isString()) {
LOG_ERROR( LOG_ERROR(
"database directory '%s' does not contain a valid parameters file", "database directory '%s' does not contain a valid parameters file",
databaseDirectory); databaseDirectory);
TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory);
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
res = TRI_ERROR_ARANGO_ILLEGAL_PARAMETER_FILE; res = TRI_ERROR_ARANGO_ILLEGAL_PARAMETER_FILE;
break; break;
} }
std::string dbname = nameSlice.copyString();
databaseName = databaseName = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, dbname.c_str());
TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, nameJson->_value._string.data,
nameJson->_value._string.length - 1);
// ......................................................................... // .........................................................................
// setup defaults // setup defaults
@ -590,7 +582,6 @@ static int OpenDatabases(TRI_server_t* server, regex_t* regex, bool isUpgrade) {
// use defaults // use defaults
TRI_GetDatabaseDefaultsServer(server, &defaults); TRI_GetDatabaseDefaultsServer(server, &defaults);
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
if (databaseName == nullptr) { if (databaseName == nullptr) {
TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory); TRI_FreeString(TRI_CORE_MEM_ZONE, databaseDirectory);