mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Update Mroonga to the latest version on 2017-10-10T23:15:25+0900
This commit is contained in:
@@ -56,9 +56,9 @@ namespace mrn {
|
||||
if (cache_) {
|
||||
void *db_address;
|
||||
GRN_HASH_EACH(ctx_, cache_, id, NULL, 0, &db_address, {
|
||||
grn_obj *db;
|
||||
Database *db;
|
||||
memcpy(&db, db_address, sizeof(grn_obj *));
|
||||
grn_obj_unlink(ctx_, db);
|
||||
delete db;
|
||||
});
|
||||
grn_hash_close(ctx_, cache_);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace mrn {
|
||||
DBUG_RETURN(true);
|
||||
}
|
||||
|
||||
int DatabaseManager::open(const char *path, grn_obj **db) {
|
||||
int DatabaseManager::open(const char *path, Database **db) {
|
||||
MRN_DBUG_ENTER_METHOD();
|
||||
|
||||
int error = 0;
|
||||
@@ -100,36 +100,54 @@ namespace mrn {
|
||||
mapper.db_name(), strlen(mapper.db_name()),
|
||||
&db_address);
|
||||
if (id == GRN_ID_NIL) {
|
||||
grn_obj *grn_db;
|
||||
struct stat db_stat;
|
||||
if (stat(mapper.db_path(), &db_stat)) {
|
||||
GRN_LOG(ctx_, GRN_LOG_INFO,
|
||||
"database not found. creating...: <%s>", mapper.db_path());
|
||||
if (path[0] == FN_CURLIB &&
|
||||
(path[1] == FN_LIBCHAR || path[1] == FN_LIBCHAR2)) {
|
||||
mrn_is_directory_separator(path[1])) {
|
||||
ensure_database_directory();
|
||||
}
|
||||
*db = grn_db_create(ctx_, mapper.db_path(), NULL);
|
||||
grn_db = grn_db_create(ctx_, mapper.db_path(), NULL);
|
||||
if (ctx_->rc) {
|
||||
error = ER_CANT_CREATE_TABLE;
|
||||
my_message(error, ctx_->errbuf, MYF(0));
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
} else {
|
||||
*db = grn_db_open(ctx_, mapper.db_path());
|
||||
grn_db = grn_db_open(ctx_, mapper.db_path());
|
||||
if (ctx_->rc) {
|
||||
error = ER_CANT_OPEN_FILE;
|
||||
my_message(error, ctx_->errbuf, MYF(0));
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
}
|
||||
*db = new Database(ctx_, grn_db);
|
||||
grn_hash_add(ctx_, cache_,
|
||||
mapper.db_name(), strlen(mapper.db_name()),
|
||||
&db_address, NULL);
|
||||
memcpy(db_address, db, sizeof(grn_obj *));
|
||||
error = ensure_normalizers_registered(*db);
|
||||
memcpy(db_address, db, sizeof(Database *));
|
||||
error = ensure_normalizers_registered((*db)->get());
|
||||
if (!error) {
|
||||
if ((*db)->is_broken()) {
|
||||
error = ER_CANT_OPEN_FILE;
|
||||
char error_message[MRN_MESSAGE_BUFFER_SIZE];
|
||||
snprintf(error_message, MRN_MESSAGE_BUFFER_SIZE,
|
||||
"mroonga: database: open: "
|
||||
"The database maybe broken. "
|
||||
"We recommend you to recreate the database. "
|
||||
"If the database isn't broken, "
|
||||
"you can remove this error by running "
|
||||
"'groonga %s table_remove mroonga_operations' "
|
||||
"on server. But the latter isn't recommended.",
|
||||
mapper.db_path());
|
||||
my_message(error, error_message, MYF(0));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
memcpy(db, db_address, sizeof(grn_obj *));
|
||||
grn_ctx_use(ctx_, *db);
|
||||
memcpy(db, db_address, sizeof(Database *));
|
||||
grn_ctx_use(ctx_, (*db)->get());
|
||||
}
|
||||
|
||||
DBUG_RETURN(error);
|
||||
@@ -150,10 +168,11 @@ namespace mrn {
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
grn_obj *db = NULL;
|
||||
memcpy(&db, db_address, sizeof(grn_obj *));
|
||||
Database *db = NULL;
|
||||
memcpy(&db, db_address, sizeof(Database *));
|
||||
grn_ctx_use(ctx_, db->get());
|
||||
if (db) {
|
||||
grn_obj_close(ctx_, db);
|
||||
delete db;
|
||||
}
|
||||
|
||||
grn_hash_delete_by_id(ctx_, cache_, id, NULL);
|
||||
@@ -173,29 +192,35 @@ namespace mrn {
|
||||
mapper.db_name(), strlen(mapper.db_name()),
|
||||
&db_address);
|
||||
|
||||
grn_obj *db = NULL;
|
||||
Database *db = NULL;
|
||||
if (id == GRN_ID_NIL) {
|
||||
struct stat dummy;
|
||||
if (stat(mapper.db_path(), &dummy) == 0) {
|
||||
db = grn_db_open(ctx_, mapper.db_path());
|
||||
grn_obj *grn_db = grn_db_open(ctx_, mapper.db_path());
|
||||
db = new Database(ctx_, grn_db);
|
||||
}
|
||||
} else {
|
||||
memcpy(&db, db_address, sizeof(grn_obj *));
|
||||
memcpy(&db, db_address, sizeof(Database *));
|
||||
grn_ctx_use(ctx_, db->get());
|
||||
}
|
||||
|
||||
if (!db) {
|
||||
DBUG_RETURN(false);
|
||||
}
|
||||
|
||||
if (grn_obj_remove(ctx_, db) == GRN_SUCCESS) {
|
||||
if (db->remove() == GRN_SUCCESS) {
|
||||
if (id != GRN_ID_NIL) {
|
||||
grn_hash_delete_by_id(ctx_, cache_, id, NULL);
|
||||
}
|
||||
delete db;
|
||||
DBUG_RETURN(true);
|
||||
} else {
|
||||
GRN_LOG(ctx_, GRN_LOG_ERROR,
|
||||
"failed to drop database: <%s>: <%s>",
|
||||
mapper.db_path(), ctx_->errbuf);
|
||||
if (id == GRN_ID_NIL) {
|
||||
delete db;
|
||||
}
|
||||
DBUG_RETURN(false);
|
||||
}
|
||||
}
|
||||
@@ -223,22 +248,28 @@ namespace mrn {
|
||||
break;
|
||||
}
|
||||
void *db_address;
|
||||
grn_obj *db;
|
||||
Database *db;
|
||||
grn_hash_cursor_get_value(ctx_, cursor, &db_address);
|
||||
memcpy(&db, db_address, sizeof(grn_obj *));
|
||||
memcpy(&db, db_address, sizeof(Database *));
|
||||
grn_ctx_use(ctx_, db->get());
|
||||
grn_rc rc = grn_hash_cursor_delete(ctx_, cursor, NULL);
|
||||
if (rc) {
|
||||
error = ER_ERROR_ON_READ;
|
||||
my_message(error, ctx_->errbuf, MYF(0));
|
||||
break;
|
||||
}
|
||||
grn_obj_close(ctx_, db);
|
||||
delete db;
|
||||
}
|
||||
grn_hash_cursor_close(ctx_, cursor);
|
||||
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
const char *DatabaseManager::error_message() {
|
||||
MRN_DBUG_ENTER_METHOD();
|
||||
DBUG_RETURN(ctx_->errbuf);
|
||||
}
|
||||
|
||||
void DatabaseManager::mkdir_p(const char *directory) {
|
||||
MRN_DBUG_ENTER_METHOD();
|
||||
|
||||
@@ -246,8 +277,7 @@ namespace mrn {
|
||||
char sub_directory[MRN_MAX_PATH_SIZE];
|
||||
sub_directory[0] = '\0';
|
||||
while (true) {
|
||||
if (directory[i] == FN_LIBCHAR ||
|
||||
directory[i] == FN_LIBCHAR2 ||
|
||||
if (mrn_is_directory_separator(directory[i]) ||
|
||||
directory[i] == '\0') {
|
||||
sub_directory[i] = '\0';
|
||||
struct stat directory_status;
|
||||
@@ -290,8 +320,10 @@ namespace mrn {
|
||||
|
||||
const char *last_path_separator;
|
||||
last_path_separator = strrchr(path_prefix, FN_LIBCHAR);
|
||||
#ifdef FN_LIBCHAR2
|
||||
if (!last_path_separator)
|
||||
last_path_separator = strrchr(path_prefix, FN_LIBCHAR2);
|
||||
#endif
|
||||
if (!last_path_separator)
|
||||
DBUG_VOID_RETURN;
|
||||
if (path_prefix == last_path_separator)
|
||||
|
Reference in New Issue
Block a user