1
0
Fork 0

cap constraint for replication logger

This commit is contained in:
Jan Steemann 2013-07-31 16:56:56 +02:00
parent 8b571fcc65
commit 48fbdb1b6a
12 changed files with 182 additions and 108 deletions

View File

@ -208,8 +208,8 @@ static TRI_json_t* JsonCapConstraint (TRI_index_t* idx,
////////////////////////////////////////////////////////////////////////////////
static void RemoveIndexCapConstraint (TRI_index_t* idx,
TRI_primary_collection_t* collection) {
collection->_capConstraint = NULL;
TRI_primary_collection_t* primary) {
primary->_capConstraint = NULL;
}
////////////////////////////////////////////////////////////////////////////////
@ -288,6 +288,11 @@ TRI_index_t* TRI_CreateCapConstraint (struct TRI_primary_collection_s* primary,
TRI_index_t* idx;
cap = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_cap_constraint_t), false);
if (cap == NULL) {
return NULL;
}
idx = &cap->base;
idx->typeName = TypeNameCapConstraint;

View File

@ -693,7 +693,7 @@ void RestReplicationHandler::handleCommandLoggerSetConfig () {
int res = TRI_ConfigureReplicationLogger(_vocbase->_replicationLogger, &config);
if (res != TRI_ERROR_NO_ERROR) {
if (res == TRI_ERROR_REPLICATION_INVALID_CONFIGURATION) {
if (res == TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION) {
generateError(HttpResponse::BAD, res);
}
else {
@ -1771,7 +1771,7 @@ void RestReplicationHandler::handleCommandApplierSetConfig () {
TRI_DestroyConfigurationReplicationApplier(&config);
if (res != TRI_ERROR_NO_ERROR) {
if (res == TRI_ERROR_REPLICATION_INVALID_CONFIGURATION ||
if (res == TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION ||
res == TRI_ERROR_REPLICATION_RUNNING) {
generateError(HttpResponse::BAD, res);
}
@ -1864,7 +1864,7 @@ void RestReplicationHandler::handleCommandApplierStart () {
found);
if (res != TRI_ERROR_NO_ERROR) {
if (res == TRI_ERROR_REPLICATION_INVALID_CONFIGURATION ||
if (res == TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION ||
res == TRI_ERROR_REPLICATION_RUNNING) {
generateError(HttpResponse::BAD, res);
}

View File

@ -3608,6 +3608,89 @@ static TRI_json_t* ExtractFieldValues (TRI_json_t const* jsonIndex,
return keyValues;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief drops an index
////////////////////////////////////////////////////////////////////////////////
static bool DropIndex (TRI_document_collection_t* document,
TRI_idx_iid_t iid,
TRI_server_id_t generatingServer,
bool extraActions) {
TRI_index_t* found;
TRI_vocbase_t* vocbase;
TRI_primary_collection_t* primary;
size_t i, n;
if (iid == 0) {
// invalid index id or primary index
return true;
}
found = NULL;
primary = &document->base;
vocbase = primary->base._vocbase;
TRI_ReadLockReadWriteLock(&vocbase->_inventoryLock);
// .............................................................................
// inside write-lock
// .............................................................................
TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
n = document->_allIndexes._length;
for (i = 0; i < n; ++i) {
TRI_index_t* idx;
idx = document->_allIndexes._buffer[i];
if (idx->_type == TRI_IDX_TYPE_PRIMARY_INDEX ||
idx->_type == TRI_IDX_TYPE_EDGE_INDEX) {
// cannot remove these index types
continue;
}
if (idx->_iid == iid) {
found = TRI_RemoveVectorPointer(&document->_allIndexes, i);
if (found != NULL && found->removeIndex != NULL) {
// notify the index about its removal
found->removeIndex(found, primary);
}
break;
}
}
RebuildIndexInfo(document);
TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
TRI_ReadUnlockReadWriteLock(&vocbase->_inventoryLock);
// .............................................................................
// outside write-lock
// .............................................................................
if (found != NULL && extraActions) {
bool removeResult;
removeResult = TRI_RemoveIndexFile(primary, found);
TRI_FreeIndex(found);
// it is safe to use _name as we hold a read-lock on the collection status
TRI_LogDropIndexReplication(vocbase,
primary->base._info._cid,
primary->base._info._name,
iid,
generatingServer);
return removeResult;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises an index with all existing documents
////////////////////////////////////////////////////////////////////////////////
@ -4057,85 +4140,23 @@ TRI_vector_pointer_t* TRI_IndexesDocumentCollection (TRI_document_collection_t*
}
////////////////////////////////////////////////////////////////////////////////
/// @brief drops an index
/// @brief drops an index, including index file removal and replication
////////////////////////////////////////////////////////////////////////////////
bool TRI_DropIndexDocumentCollection (TRI_document_collection_t* document,
TRI_idx_iid_t iid,
TRI_server_id_t generatingServer) {
TRI_index_t* found;
TRI_vocbase_t* vocbase;
TRI_primary_collection_t* primary;
size_t i, n;
return DropIndex(document, iid, generatingServer, true);
}
if (iid == 0) {
// invalid index id or primary index
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief drops an index, without index file removal and replication
////////////////////////////////////////////////////////////////////////////////
found = NULL;
primary = &document->base;
vocbase = primary->base._vocbase;
TRI_ReadLockReadWriteLock(&vocbase->_inventoryLock);
// .............................................................................
// inside write-lock
// .............................................................................
TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
n = document->_allIndexes._length;
for (i = 0; i < n; ++i) {
TRI_index_t* idx;
idx = document->_allIndexes._buffer[i];
if (idx->_type == TRI_IDX_TYPE_PRIMARY_INDEX ||
idx->_type == TRI_IDX_TYPE_EDGE_INDEX) {
// cannot remove these index types
continue;
}
if (idx->_iid == iid) {
found = TRI_RemoveVectorPointer(&document->_allIndexes, i);
if (found != NULL && found->removeIndex != NULL) {
// notify the index about its removal
found->removeIndex(found, primary);
}
break;
}
}
RebuildIndexInfo(document);
TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
TRI_ReadUnlockReadWriteLock(&vocbase->_inventoryLock);
// .............................................................................
// outside write-lock
// .............................................................................
if (found != NULL) {
bool removeResult;
removeResult = TRI_RemoveIndexFile(primary, found);
TRI_FreeIndex(found);
// it is safe to use _name as we hold a read-lock on the collection status
TRI_LogDropIndexReplication(vocbase,
primary->base._info._cid,
primary->base._info._name,
iid,
generatingServer);
return removeResult;
}
return false;
bool TRI_DropIndex2DocumentCollection (TRI_document_collection_t* document,
TRI_idx_iid_t iid,
TRI_server_id_t generatingServer) {
return DropIndex(document, iid, generatingServer, false);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -374,13 +374,21 @@ int TRI_CloseDocumentCollection (TRI_document_collection_t*);
TRI_vector_pointer_t* TRI_IndexesDocumentCollection (TRI_document_collection_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief drops an index
/// @brief drops an index, including index file removal and replication
////////////////////////////////////////////////////////////////////////////////
bool TRI_DropIndexDocumentCollection (TRI_document_collection_t*,
TRI_idx_iid_t,
TRI_server_id_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief drops an index, without index file removal and replication
////////////////////////////////////////////////////////////////////////////////
bool TRI_DropIndex2DocumentCollection (TRI_document_collection_t*,
TRI_idx_iid_t,
TRI_server_id_t);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////

View File

@ -214,7 +214,7 @@ static int LoadConfiguration (TRI_vocbase_t* vocbase,
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
}
return TRI_ERROR_REPLICATION_INVALID_CONFIGURATION;
return TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION;
}
res = TRI_ERROR_NO_ERROR;
@ -236,7 +236,7 @@ static int LoadConfiguration (TRI_vocbase_t* vocbase,
value = TRI_LookupArrayJson(json, "endpoint");
if (! TRI_IsStringJson(value)) {
res = TRI_ERROR_REPLICATION_INVALID_CONFIGURATION;
res = TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION;
}
else {
config->_endpoint = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE,
@ -406,7 +406,7 @@ static int StartApplier (TRI_replication_applier_t* applier,
}
if (applier->_configuration._endpoint == NULL) {
return SetError(applier, TRI_ERROR_REPLICATION_INVALID_CONFIGURATION, "no endpoint configured");
return SetError(applier, TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION, "no endpoint configured");
}
fetcher = (void*) TRI_CreateContinuousSyncerReplication(applier->_vocbase,
@ -773,7 +773,7 @@ int TRI_ConfigureReplicationApplier (TRI_replication_applier_t* applier,
if (config->_endpoint == NULL || strlen(config->_endpoint) == 0) {
// no endpoint
return TRI_ERROR_REPLICATION_INVALID_CONFIGURATION;
return TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION;
}
TRI_WriteLockReadWriteLock(&applier->_statusLock);

View File

@ -74,6 +74,19 @@ extern "C" {
#define TRI_REPLICATION_HEADER_ACTIVE "x-arango-replication-active"
////////////////////////////////////////////////////////////////////////////////
/// @brief minimum number of log events to keep (lower bound for logger config)
////////////////////////////////////////////////////////////////////////////////
#define TRI_REPLICATION_LOGGER_EVENTS_MIN 16384
////////////////////////////////////////////////////////////////////////////////
/// @brief minimum cumulated size of log events to keep (lower bound for logger
/// config)
////////////////////////////////////////////////////////////////////////////////
#define TRI_REPLICATION_LOGGER_SIZE_MIN 16777216
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////

View File

@ -271,9 +271,9 @@ static void FreeCap (TRI_replication_logger_t* logger) {
primary = logger->_trxCollection->_collection->_collection;
assert(primary != NULL);
TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
TRI_FreeIndex(logger->_cap);
TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
TRI_DropIndex2DocumentCollection((TRI_document_collection_t*) primary,
logger->_cap->_iid,
TRI_GetServerId());
logger->_cap = NULL;
logger->_configuration._maxEvents = 0;
@ -289,6 +289,7 @@ static void FreeCap (TRI_replication_logger_t* logger) {
static bool CreateCap (TRI_replication_logger_t* logger) {
TRI_index_t* idx;
TRI_primary_collection_t* primary;
bool created;
primary = logger->_trxCollection->_collection->_collection;
assert(primary != NULL);
@ -299,13 +300,13 @@ static bool CreateCap (TRI_replication_logger_t* logger) {
LOG_INFO("creating cap constraint for replication logger. maxEvents: %llu, maxEventsSize: %llu",
(unsigned long long) logger->_configuration._maxEvents,
(unsigned long long) logger->_configuration._maxEventsSize);
idx = TRI_EnsureCapConstraintDocumentCollection((TRI_document_collection_t*) logger->_trxCollection->_collection->_collection,
idx = TRI_EnsureCapConstraintDocumentCollection((TRI_document_collection_t*) primary,
(size_t) logger->_configuration._maxEvents,
(int64_t) logger->_configuration._maxEventsSize,
NULL,
&created,
TRI_GetServerId());
if (idx == NULL) {
LOG_WARNING("creating cap constraint for '%s' failed", TRI_COL_NAME_REPLICATION);
return false;
@ -1424,6 +1425,15 @@ int TRI_ConfigureReplicationLogger (TRI_replication_logger_t* logger,
res = TRI_ERROR_NO_ERROR;
if (config->_maxEvents == 0 && config->_maxEventsSize == 0) {
return TRI_ERROR_REPLICATION_INVALID_LOGGER_CONFIGURATION;
}
if (config->_maxEvents < TRI_REPLICATION_LOGGER_EVENTS_MIN ||
config->_maxEventsSize < TRI_REPLICATION_LOGGER_SIZE_MIN) {
return TRI_ERROR_REPLICATION_INVALID_LOGGER_CONFIGURATION;
}
TRI_WriteLockReadWriteLock(&logger->_statusLock);
oldMaxEvents = logger->_configuration._maxEvents;
oldMaxEventsSize = logger->_configuration._maxEventsSize;

View File

@ -97,9 +97,10 @@
"ERROR_REPLICATION_UNEXPECTED_MARKER" : { "code" : 1406, "message" : "unexpected marker" },
"ERROR_REPLICATION_INVALID_APPLY_STATE" : { "code" : 1407, "message" : "invalid applier state" },
"ERROR_REPLICATION_UNEXPECTED_TRANSACTION" : { "code" : 1408, "message" : "invalid transaction" },
"ERROR_REPLICATION_INVALID_CONFIGURATION" : { "code" : 1409, "message" : "invalid replication applier configuration" },
"ERROR_REPLICATION_RUNNING" : { "code" : 1410, "message" : "cannot change applier configuration while running" },
"ERROR_REPLICATION_STOPPED" : { "code" : 1411, "message" : "replication stopped" },
"ERROR_REPLICATION_INVALID_LOGGER_CONFIGURATION" : { "code" : 1409, "message" : "invalid replication logger configuration" },
"ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION" : { "code" : 1410, "message" : "invalid replication applier configuration" },
"ERROR_REPLICATION_RUNNING" : { "code" : 1411, "message" : "cannot change applier configuration while running" },
"ERROR_REPLICATION_STOPPED" : { "code" : 1412, "message" : "replication stopped" },
"ERROR_QUERY_KILLED" : { "code" : 1500, "message" : "query killed" },
"ERROR_QUERY_PARSE" : { "code" : 1501, "message" : "%s" },
"ERROR_QUERY_EMPTY" : { "code" : 1502, "message" : "query is empty" },

View File

@ -97,9 +97,10 @@
"ERROR_REPLICATION_UNEXPECTED_MARKER" : { "code" : 1406, "message" : "unexpected marker" },
"ERROR_REPLICATION_INVALID_APPLY_STATE" : { "code" : 1407, "message" : "invalid applier state" },
"ERROR_REPLICATION_UNEXPECTED_TRANSACTION" : { "code" : 1408, "message" : "invalid transaction" },
"ERROR_REPLICATION_INVALID_CONFIGURATION" : { "code" : 1409, "message" : "invalid replication applier configuration" },
"ERROR_REPLICATION_RUNNING" : { "code" : 1410, "message" : "cannot change applier configuration while running" },
"ERROR_REPLICATION_STOPPED" : { "code" : 1411, "message" : "replication stopped" },
"ERROR_REPLICATION_INVALID_LOGGER_CONFIGURATION" : { "code" : 1409, "message" : "invalid replication logger configuration" },
"ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION" : { "code" : 1410, "message" : "invalid replication applier configuration" },
"ERROR_REPLICATION_RUNNING" : { "code" : 1411, "message" : "cannot change applier configuration while running" },
"ERROR_REPLICATION_STOPPED" : { "code" : 1412, "message" : "replication stopped" },
"ERROR_QUERY_KILLED" : { "code" : 1500, "message" : "query killed" },
"ERROR_QUERY_PARSE" : { "code" : 1501, "message" : "%s" },
"ERROR_QUERY_EMPTY" : { "code" : 1502, "message" : "query is empty" },

View File

@ -127,9 +127,10 @@ ERROR_REPLICATION_LOOP,1405,"loop detected","Will be raised when the replica con
ERROR_REPLICATION_UNEXPECTED_MARKER,1406,"unexpected marker","Will be raised when an unexpected marker is found in the replication stream."
ERROR_REPLICATION_INVALID_APPLY_STATE,1407,"invalid applier state","Will be raised when an invalid applier state file is found."
ERROR_REPLICATION_UNEXPECTED_TRANSACTION,1408,"invalid transaction","Will be raised when an unexpected transaction id is found."
ERROR_REPLICATION_INVALID_CONFIGURATION,1409,"invalid replication applier configuration","Will be raised when the configuration for the replication applier is invalid."
ERROR_REPLICATION_RUNNING,1410,"cannot change applier configuration while running","Will be raised when there is an attempt to change the configuration for the replication applier while it is running."
ERROR_REPLICATION_STOPPED,1411,"replication stopped","Special error code used to indicate the replication was stopped."
ERROR_REPLICATION_INVALID_LOGGER_CONFIGURATION,1409,"invalid replication logger configuration","Will be raised when the configuration for the replication logger is invalid."
ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION,1410,"invalid replication applier configuration","Will be raised when the configuration for the replication applier is invalid."
ERROR_REPLICATION_RUNNING,1411,"cannot change applier configuration while running","Will be raised when there is an attempt to change the configuration for the replication applier while it is running."
ERROR_REPLICATION_STOPPED,1412,"replication stopped","Special error code used to indicate the replication was stopped."
################################################################################
## ArangoDB query errors

View File

@ -93,7 +93,8 @@ void TRI_InitialiseErrorMessages (void) {
REG_ERROR(ERROR_REPLICATION_UNEXPECTED_MARKER, "unexpected marker");
REG_ERROR(ERROR_REPLICATION_INVALID_APPLY_STATE, "invalid applier state");
REG_ERROR(ERROR_REPLICATION_UNEXPECTED_TRANSACTION, "invalid transaction");
REG_ERROR(ERROR_REPLICATION_INVALID_CONFIGURATION, "invalid replication applier configuration");
REG_ERROR(ERROR_REPLICATION_INVALID_LOGGER_CONFIGURATION, "invalid replication logger configuration");
REG_ERROR(ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION, "invalid replication applier configuration");
REG_ERROR(ERROR_REPLICATION_RUNNING, "cannot change applier configuration while running");
REG_ERROR(ERROR_REPLICATION_STOPPED, "replication stopped");
REG_ERROR(ERROR_QUERY_KILLED, "query killed");

View File

@ -195,13 +195,16 @@ extern "C" {
/// Will be raised when an invalid applier state file is found.
/// - 1408: @LIT{invalid transaction}
/// Will be raised when an unexpected transaction id is found.
/// - 1409: @LIT{invalid replication applier configuration}
/// - 1409: @LIT{invalid replication logger configuration}
/// Will be raised when the configuration for the replication logger is
/// invalid.
/// - 1410: @LIT{invalid replication applier configuration}
/// Will be raised when the configuration for the replication applier is
/// invalid.
/// - 1410: @LIT{cannot change applier configuration while running}
/// - 1411: @LIT{cannot change applier configuration while running}
/// Will be raised when there is an attempt to change the configuration for
/// the replication applier while it is running.
/// - 1411: @LIT{replication stopped}
/// - 1412: @LIT{replication stopped}
/// Special error code used to indicate the replication was stopped.
/// - 1500: @LIT{query killed}
/// Will be raised when a running query is killed by an explicit admin
@ -1298,7 +1301,17 @@ void TRI_InitialiseErrorMessages (void);
#define TRI_ERROR_REPLICATION_UNEXPECTED_TRANSACTION (1408)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1409: ERROR_REPLICATION_INVALID_CONFIGURATION
/// @brief 1409: ERROR_REPLICATION_INVALID_LOGGER_CONFIGURATION
///
/// invalid replication logger configuration
///
/// Will be raised when the configuration for the replication logger is invalid.
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_REPLICATION_INVALID_LOGGER_CONFIGURATION (1409)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1410: ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION
///
/// invalid replication applier configuration
///
@ -1306,10 +1319,10 @@ void TRI_InitialiseErrorMessages (void);
/// invalid.
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_REPLICATION_INVALID_CONFIGURATION (1409)
#define TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION (1410)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1410: ERROR_REPLICATION_RUNNING
/// @brief 1411: ERROR_REPLICATION_RUNNING
///
/// cannot change applier configuration while running
///
@ -1317,17 +1330,17 @@ void TRI_InitialiseErrorMessages (void);
/// replication applier while it is running.
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_REPLICATION_RUNNING (1410)
#define TRI_ERROR_REPLICATION_RUNNING (1411)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1411: ERROR_REPLICATION_STOPPED
/// @brief 1412: ERROR_REPLICATION_STOPPED
///
/// replication stopped
///
/// Special error code used to indicate the replication was stopped.
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_REPLICATION_STOPPED (1411)
#define TRI_ERROR_REPLICATION_STOPPED (1412)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1500: ERROR_QUERY_KILLED