Esempio n. 1
0
static int StartApplier (TRI_replication_applier_t* applier,
                         TRI_voc_tick_t initialTick,
                         bool useTick) {
  TRI_replication_applier_state_t* state;
  void* fetcher;

  state = &applier->_state;

  if (state->_active) {
    return TRI_ERROR_INTERNAL;
  }

  if (applier->_configuration._endpoint == NULL) {
    return SetError(applier, TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION, "no endpoint configured");
  }
  
  if (applier->_configuration._database == NULL) {
    return SetError(applier, TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION, "no database configured");
  }
  
  fetcher = (void*) TRI_CreateContinuousSyncerReplication(applier->_vocbase, 
                                                          &applier->_configuration,
                                                          initialTick,
                                                          useTick);

  if (fetcher == NULL) {
    return TRI_ERROR_OUT_OF_MEMORY;
  }
  
 
  // reset error 
  if (state->_lastError._msg != NULL) {
    TRI_FreeString(TRI_CORE_MEM_ZONE, state->_lastError._msg);
    state->_lastError._msg = NULL;
  }

  state->_lastError._code = TRI_ERROR_NO_ERROR;
  
  TRI_GetTimeStampReplication(state->_lastError._time, sizeof(state->_lastError._time) - 1);

  
  SetTerminateFlag(applier, false); 
  state->_active = true;
  
  TRI_InitThread(&applier->_thread);

  if (! TRI_StartThread(&applier->_thread, "[applier]", ApplyThread, fetcher)) {
    TRI_DeleteContinuousSyncerReplication(fetcher);

    return TRI_ERROR_INTERNAL;
  }

  LOG_INFO("started replication applier for database '%s'",
           applier->_databaseName);

  return TRI_ERROR_NO_ERROR;
}
static int StartApplier (TRI_replication_applier_t* applier,
                         TRI_voc_tick_t initialTick,
                         bool useTick) {
  TRI_replication_applier_state_t* state = &applier->_state;

  if (state->_active) {
    return TRI_ERROR_INTERNAL;
  }

  if (applier->_configuration._endpoint == nullptr) {
    return SetError(applier, TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION, "no endpoint configured");
  }

  if (applier->_configuration._database == nullptr) {
    return SetError(applier, TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION, "no database configured");
  }
  
  // TODO: prevent restart of the applier with a tick after a shutdown

  auto fetcher = new triagens::arango::ContinuousSyncer(applier->_server,
                                                        applier->_vocbase,
                                                        &applier->_configuration,
                                                        initialTick,
                                                        useTick);

  if (fetcher == nullptr) {
    return TRI_ERROR_OUT_OF_MEMORY;
  }

  // reset error
  if (state->_lastError._msg != nullptr) {
    TRI_FreeString(TRI_CORE_MEM_ZONE, state->_lastError._msg);
    state->_lastError._msg = nullptr;
  }

  state->_lastError._code = TRI_ERROR_NO_ERROR;

  TRI_GetTimeStampReplication(state->_lastError._time, sizeof(state->_lastError._time) - 1);


  SetTerminateFlag(applier, false);
  state->_active = true;

  TRI_InitThread(&applier->_thread);

  if (! TRI_StartThread(&applier->_thread, nullptr, "[applier]", ApplyThread, static_cast<void*>(fetcher))) {
    delete fetcher;

    return TRI_ERROR_INTERNAL;
  }

  LOG_INFO("started replication applier for database '%s'",
           applier->_databaseName);

  return TRI_ERROR_NO_ERROR;
}