|
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.h#5 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef INDEX_STATE_H
|
|
Packit Service |
310c69 |
#define INDEX_STATE_H 1
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "buffer.h"
|
|
Packit Service |
310c69 |
#include "indexComponent.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Used here and in SingleFileLayout.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef enum {
|
|
Packit Service |
310c69 |
IS_SAVE,
|
|
Packit Service |
310c69 |
IS_CHECKPOINT,
|
|
Packit Service |
310c69 |
NO_SAVE = 9999,
|
|
Packit Service |
310c69 |
} IndexSaveType;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Used in getStateIndexStateBuffer to identify whether the index state buffer
|
|
Packit Service |
310c69 |
* is for the index being loaded or the index being saved.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
typedef enum {
|
|
Packit Service |
310c69 |
IO_READ = 0x1,
|
|
Packit Service |
310c69 |
IO_WRITE = 0x2,
|
|
Packit Service |
310c69 |
} IOAccessMode;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The index state structure controls the loading and saving of the index
|
|
Packit Service |
310c69 |
* state.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef struct indexState {
|
|
Packit Service |
310c69 |
struct indexLayout *layout;
|
|
Packit Service |
310c69 |
unsigned int zoneCount; // number of index zones to use
|
|
Packit Service |
310c69 |
unsigned int loadZones;
|
|
Packit Service |
310c69 |
unsigned int loadSlot;
|
|
Packit Service |
310c69 |
unsigned int saveSlot;
|
|
Packit Service |
310c69 |
unsigned int count; // count of registered entries (<= length)
|
|
Packit Service |
310c69 |
unsigned int length; // total span of array allocation
|
|
Packit Service |
310c69 |
bool saving; // incremental save in progress
|
|
Packit Service |
310c69 |
IndexComponent *entries[]; // array of index component entries
|
|
Packit Service |
310c69 |
} IndexState;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Make an index state object,
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] layout The index layout.
|
|
Packit Service |
310c69 |
* @param [in] numZones The number of zones to use.
|
|
Packit Service |
310c69 |
* @param [in] maxComponents The maximum number of components to be handled.
|
|
Packit Service |
310c69 |
* @param [out] statePtr Where to store the index state object.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeIndexState(struct indexLayout *layout,
|
|
Packit Service |
310c69 |
unsigned int numZones,
|
|
Packit Service |
310c69 |
unsigned int maxComponents,
|
|
Packit Service |
310c69 |
IndexState **statePtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Free an index state (generically).
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param statePtr The pointer to the index state to be freed and
|
|
Packit Service |
310c69 |
* set to NULL.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeIndexState(IndexState **statePtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Add an index component to an index state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index directory in which to add this component.
|
|
Packit Service |
310c69 |
* @param info The index component file specification.
|
|
Packit Service |
310c69 |
* @param data The per-component data structure.
|
|
Packit Service |
310c69 |
* @param context The load/save context of the component.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
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 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Load index state
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state.
|
|
Packit Service |
310c69 |
* @param replayPtr If set, the place to hold whether a replay is required.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int loadIndexState(IndexState *state, bool *replayPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Save the current index state, including the open chapter.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int saveIndexState(IndexState *state) __attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Prepare to save the index state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state the index state
|
|
Packit Service |
310c69 |
* @param saveType whether a checkpoint or save
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int prepareToSaveIndexState(IndexState *state, IndexSaveType saveType)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Write index checkpoint non-incrementally (for testing).
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int writeIndexStateCheckpoint(IndexState *state)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Sets up an index state checkpoint which will proceed incrementally.
|
|
Packit Service |
310c69 |
* May create the directory but does not actually write any data.
|
|
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 |
int startIndexStateCheckpoint(IndexState *state)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Perform operations on index state checkpoints that are synchronized to
|
|
Packit Service |
310c69 |
* the chapter writer thread.
|
|
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 |
int performIndexStateCheckpointChapterSynchronizedSaves(IndexState *state)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Performs zone-specific (and, for zone 0, general) incremental checkpointing.
|
|
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 [out] completed Set to whether the checkpoint has completed
|
|
Packit Service |
310c69 |
* for this zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int performIndexStateCheckpointInZone(IndexState *state,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
CompletionStatus *completed)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Force the completion of an incremental index state checkpoint
|
|
Packit Service |
310c69 |
* for a particular zone.
|
|
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 [out] completed Set to whether the checkpoint has completed
|
|
Packit Service |
310c69 |
* for this zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int finishIndexStateCheckpointInZone(IndexState *state,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
CompletionStatus *completed)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Force the completion of an incremental index state checkpoint once
|
|
Packit Service |
310c69 |
* all zones are completed.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] state The index state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int finishIndexStateCheckpoint(IndexState *state)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Aborts an index state checkpoint which is proceeding incrementally
|
|
Packit Service |
310c69 |
* for a particular zone.
|
|
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 [out] completed Set to whether the checkpoint has completed or
|
|
Packit Service |
310c69 |
* aborted for this zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
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 |
/**
|
|
Packit Service |
310c69 |
* Aborts an index state checkpoint which is proceeding incrementally,
|
|
Packit Service |
310c69 |
* once all the zones are aborted.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] state The index state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int abortIndexStateCheckpoint(IndexState *state);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Remove or disable the index state data, for testing.
|
|
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 |
* @note the return value of this function is frequently ignored
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int discardIndexStateData(IndexState *state);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Discard the last index state save, for testing.
|
|
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 |
* @note the return value of this function is frequently ignored
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int discardLastIndexStateSave(IndexState *state);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Find index component, for testing.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state
|
|
Packit Service |
310c69 |
* @param info The index component file specification
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The index component, or NULL if not found
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
IndexComponent *findIndexComponent(const IndexState *state,
|
|
Packit Service |
310c69 |
const IndexComponentInfo *info)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the indexStateBuffer for a specified mode.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state.
|
|
Packit Service |
310c69 |
* @param mode One of IO_READ or IO_WRITE.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the index state buffer
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
Buffer *getStateIndexStateBuffer(IndexState *state, IOAccessMode mode)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Open a BufferedReader for a specified state, kind, and zone.
|
|
Packit Service |
310c69 |
* This helper function is used by IndexComponent.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state.
|
|
Packit Service |
310c69 |
* @param kind The kind if index save region to open.
|
|
Packit Service |
310c69 |
* @param zone The zone number for the region.
|
|
Packit Service |
310c69 |
* @param readerPtr Where to store the BufferedReader.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
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 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Open a BufferedWriter for a specified state, kind, and zone.
|
|
Packit Service |
310c69 |
* This helper function is used by IndexComponent.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state.
|
|
Packit Service |
310c69 |
* @param kind The kind if index save region to open.
|
|
Packit Service |
310c69 |
* @param zone The zone number for the region.
|
|
Packit Service |
310c69 |
* @param writerPtr Where to store the BufferedWriter.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
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 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif // INDEX_STATE_H
|