|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/uds-releases/jasper/src/uds/indexState.c#6 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "indexState.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "errors.h"
|
|
Packit Service |
310c69 |
#include "indexComponent.h"
|
|
Packit Service |
310c69 |
#include "indexLayout.h"
|
|
Packit Service |
310c69 |
#include "logger.h"
|
|
Packit Service |
310c69 |
#include "memoryAlloc.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int makeIndexState(IndexLayout *layout,
|
|
Packit Service |
310c69 |
unsigned int numZones,
|
|
Packit Service |
310c69 |
unsigned int maxComponents,
|
|
Packit Service |
310c69 |
IndexState **statePtr)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
if (maxComponents == 0) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(
|
|
Packit Service |
310c69 |
UDS_INVALID_ARGUMENT, "cannot make index state with maxComponents 0");
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
IndexState *state = NULL;
|
|
Packit Service |
310c69 |
int result = ALLOCATE_EXTENDED(IndexState, maxComponents, IndexComponent *,
|
|
Packit Service |
310c69 |
"index state", &state);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
state->count = 0;
|
|
Packit Service |
310c69 |
state->layout = layout;
|
|
Packit Service |
310c69 |
state->length = maxComponents;
|
|
Packit Service |
310c69 |
state->loadZones = 0;
|
|
Packit Service |
310c69 |
state->loadSlot = UINT_MAX;
|
|
Packit Service |
310c69 |
state->saveSlot = UINT_MAX;
|
|
Packit Service |
310c69 |
state->saving = false;
|
|
Packit Service |
310c69 |
state->zoneCount = numZones;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
*statePtr = state;
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
void freeIndexState(IndexState **statePtr)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
IndexState *state = *statePtr;
|
|
Packit Service |
310c69 |
*statePtr = NULL;
|
|
Packit Service |
310c69 |
if (state != NULL) {
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
freeIndexComponent(&state->entries[i]);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
FREE(state);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Add a component to the index state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state.
|
|
Packit Service |
310c69 |
* @param component The index component.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static int addComponentToIndexState(IndexState *state,
|
|
Packit Service |
310c69 |
IndexComponent *component)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
if (findIndexComponent(state, component->info) != NULL) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(
|
|
Packit Service |
310c69 |
UDS_INVALID_ARGUMENT, "cannot add state component %s: already present",
|
|
Packit Service |
310c69 |
component->info->name);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
if (state->count >= state->length) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(
|
|
Packit Service |
310c69 |
UDS_RESOURCE_LIMIT_EXCEEDED,
|
|
Packit Service |
310c69 |
"cannot add state component %s, %u components already added",
|
|
Packit Service |
310c69 |
component->info->name, state->count);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
state->entries[state->count] = component;
|
|
Packit Service |
310c69 |
++state->count;
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int addIndexStateComponent(IndexState *state,
|
|
Packit Service |
310c69 |
const IndexComponentInfo *info,
|
|
Packit Service |
310c69 |
void *data,
|
|
Packit Service |
310c69 |
void *context)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
IndexComponent *component = NULL;
|
|
Packit Service |
310c69 |
int result = makeIndexComponent(state, info, state->zoneCount, data, context,
|
|
Packit Service |
310c69 |
&component);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result,
|
|
Packit Service |
310c69 |
"cannot make region index component");
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
result = addComponentToIndexState(state, component);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
freeIndexComponent(&component);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
IndexComponent *findIndexComponent(const IndexState *state,
|
|
Packit Service |
310c69 |
const IndexComponentInfo *info)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
if (info == component->info) {
|
|
Packit Service |
310c69 |
return component;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return NULL;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
static const char *indexSaveTypeName(IndexSaveType saveType)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return saveType == IS_SAVE ? "save" : "checkpoint";
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int loadIndexState(IndexState *state, bool *replayPtr)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
int result = findLatestIndexSaveSlot(state->layout, &state->loadZones,
|
|
Packit Service |
310c69 |
&state->loadSlot);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
bool replayRequired = false;
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
result = readIndexComponent(component);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
if (!missingIndexComponentRequiresReplay(component)) {
|
|
Packit Service |
310c69 |
state->loadZones = 0;
|
|
Packit Service |
310c69 |
state->loadSlot = UINT_MAX;
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result, "index component %s",
|
|
Packit Service |
310c69 |
indexComponentName(component));
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
replayRequired = true;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
state->loadZones = 0;
|
|
Packit Service |
310c69 |
state->loadSlot = UINT_MAX;
|
|
Packit Service |
310c69 |
if (replayPtr != NULL) {
|
|
Packit Service |
310c69 |
*replayPtr = replayRequired;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int prepareToSaveIndexState(IndexState *state, IndexSaveType saveType)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
if (state->saving) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(UDS_BAD_STATE,
|
|
Packit Service |
310c69 |
"already saving the index state");
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
int result = setupIndexSaveSlot(state->layout, state->zoneCount, saveType,
|
|
Packit Service |
310c69 |
&state->saveSlot);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result, "cannot prepare index %s",
|
|
Packit Service |
310c69 |
indexSaveTypeName(saveType));
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Complete the saving of an index state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state the index state
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static int completeIndexSaving(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
state->saving = false;
|
|
Packit Service |
310c69 |
int result = commitIndexSave(state->layout, state->saveSlot);
|
|
Packit Service |
310c69 |
state->saveSlot = UINT_MAX;
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result, "cannot commit index state");
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
static int cleanupSave(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
int result = cancelIndexSave(state->layout, state->saveSlot);
|
|
Packit Service |
310c69 |
state->saveSlot = UINT_MAX;
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result, "cannot cancel index save");
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int saveIndexState(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
int result = prepareToSaveIndexState(state, IS_SAVE);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
result = writeIndexComponent(component);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
cleanupSave(state);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return completeIndexSaving(state);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int writeIndexStateCheckpoint(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
int result = prepareToSaveIndexState(state, IS_CHECKPOINT);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
if (skipIndexComponentOnCheckpoint(component)) {
|
|
Packit Service |
310c69 |
continue;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = writeIndexComponent(component);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
cleanupSave(state);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
return completeIndexSaving(state);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int startIndexStateCheckpoint(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
int result = prepareToSaveIndexState(state, IS_CHECKPOINT);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
state->saving = true;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
if (skipIndexComponentOnCheckpoint(component)) {
|
|
Packit Service |
310c69 |
continue;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = startIndexComponentIncrementalSave(component);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
abortIndexStateCheckpoint(state);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int performIndexStateCheckpointChapterSynchronizedSaves(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
if (!state->saving) {
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
if (skipIndexComponentOnCheckpoint(component) ||
|
|
Packit Service |
310c69 |
!deferIndexComponentCheckpointToChapterWriter(component)) {
|
|
Packit Service |
310c69 |
continue;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
int result = performIndexComponentChapterWriterSave(component);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Wrapper function to do a zone-based checkpoint operation.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] state the index state
|
|
Packit Service |
310c69 |
* @param [in] zone the zone number
|
|
Packit Service |
310c69 |
* @param [in] compFunc the index component function to use
|
|
Packit Service |
310c69 |
* @param [out] completed if non-NULL, where to save the completion status
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static int doIndexStateCheckpointInZone(IndexState *state,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
int (*compFunc)(IndexComponent *,
|
|
Packit Service |
310c69 |
unsigned int,
|
|
Packit Service |
310c69 |
CompletionStatus *),
|
|
Packit Service |
310c69 |
CompletionStatus *completed)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
if (!state->saving) {
|
|
Packit Service |
310c69 |
if (completed != NULL) {
|
|
Packit Service |
310c69 |
*completed = CS_COMPLETED_PREVIOUSLY;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
CompletionStatus status = CS_COMPLETED_PREVIOUSLY;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
if (skipIndexComponentOnCheckpoint(component)) {
|
|
Packit Service |
310c69 |
continue;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
if (zone > 0 && !component->info->multiZone) {
|
|
Packit Service |
310c69 |
continue;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
CompletionStatus componentStatus = CS_NOT_COMPLETED;
|
|
Packit Service |
310c69 |
int result = (*compFunc)(component, zone, &componentStatus);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
// compute rolling least status
|
|
Packit Service |
310c69 |
if (componentStatus < status) {
|
|
Packit Service |
310c69 |
status = componentStatus;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
if (completed != NULL) {
|
|
Packit Service |
310c69 |
*completed = status;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int performIndexStateCheckpointInZone(IndexState *state,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
CompletionStatus *completed)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return doIndexStateCheckpointInZone(state, zone,
|
|
Packit Service |
310c69 |
&performIndexComponentZoneSave,
|
|
Packit Service |
310c69 |
completed);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int finishIndexStateCheckpointInZone(IndexState *state,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
CompletionStatus *completed)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return doIndexStateCheckpointInZone(state, zone,
|
|
Packit Service |
310c69 |
&finishIndexComponentZoneSave,
|
|
Packit Service |
310c69 |
completed);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int abortIndexStateCheckpointInZone(IndexState *state,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
CompletionStatus *completed)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return doIndexStateCheckpointInZone(state, zone,
|
|
Packit Service |
310c69 |
&abortIndexComponentZoneSave, completed);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int finishIndexStateCheckpoint(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
if (!state->saving) {
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
if (skipIndexComponentOnCheckpoint(component)) {
|
|
Packit Service |
310c69 |
continue;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
int result = finishIndexComponentIncrementalSave(component);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
abortIndexStateCheckpoint(state);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
int result = completeIndexSaving(state);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int abortIndexStateCheckpoint(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
if (!state->saving) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(UDS_BAD_STATE,
|
|
Packit Service |
310c69 |
"not saving the index state");
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
logError("aborting index state checkpoint");
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
int result = UDS_SUCCESS;
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < state->count; ++i) {
|
|
Packit Service |
310c69 |
IndexComponent *component = state->entries[i];
|
|
Packit Service |
310c69 |
if (skipIndexComponentOnCheckpoint(component)) {
|
|
Packit Service |
310c69 |
continue;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
int tmp = abortIndexComponentIncrementalSave(component);
|
|
Packit Service |
310c69 |
if (result == UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
result = tmp;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
cleanupSave(state);
|
|
Packit Service |
310c69 |
state->saving = false;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int discardIndexStateData(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
int result = discardIndexSaves(state->layout, true);
|
|
Packit Service |
310c69 |
state->saveSlot = UINT_MAX;
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result,
|
|
Packit Service |
310c69 |
"%s: cannot destroy all index saves",
|
|
Packit Service |
310c69 |
__func__);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int discardLastIndexStateSave(IndexState *state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
int result = discardIndexSaves(state->layout, false);
|
|
Packit Service |
310c69 |
state->saveSlot = UINT_MAX;
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result,
|
|
Packit Service |
310c69 |
"%s: cannot destroy latest index save",
|
|
Packit Service |
310c69 |
__func__);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
Buffer *getStateIndexStateBuffer(IndexState *state, IOAccessMode mode)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
unsigned int slot = mode == IO_READ ? state->loadSlot : state->saveSlot;
|
|
Packit Service |
310c69 |
return getIndexStateBuffer(state->layout, slot);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int openStateBufferedReader(IndexState *state,
|
|
Packit Service |
310c69 |
RegionKind kind,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
BufferedReader **readerPtr)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return openIndexBufferedReader(state->layout, state->loadSlot, kind, zone,
|
|
Packit Service |
310c69 |
readerPtr);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int openStateBufferedWriter(IndexState *state,
|
|
Packit Service |
310c69 |
RegionKind kind,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
BufferedWriter **writerPtr)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return openIndexBufferedWriter(state->layout, state->saveSlot, kind, zone,
|
|
Packit Service |
310c69 |
writerPtr);
|
|
Packit Service |
310c69 |
}
|