|
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/indexComponent.h#5 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef INDEX_COMPONENT_H
|
|
Packit Service |
310c69 |
#define INDEX_COMPONENT_H 1
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "common.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "bufferedReader.h"
|
|
Packit Service |
310c69 |
#include "bufferedWriter.h"
|
|
Packit Service |
310c69 |
#include "compiler.h"
|
|
Packit Service |
310c69 |
#include "regionIdentifiers.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef enum completionStatus {
|
|
Packit Service |
310c69 |
CS_NOT_COMPLETED, // operation has not completed
|
|
Packit Service |
310c69 |
CS_JUST_COMPLETED, // operation just completed
|
|
Packit Service |
310c69 |
CS_COMPLETED_PREVIOUSLY // operation completed previously
|
|
Packit Service |
310c69 |
} CompletionStatus;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct readPortal {
|
|
Packit Service |
310c69 |
struct indexComponent *component;
|
|
Packit Service |
310c69 |
BufferedReader **readers;
|
|
Packit Service |
310c69 |
unsigned int zones;
|
|
Packit Service |
310c69 |
} ReadPortal;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Prototype for functions which can load an index component from its
|
|
Packit Service |
310c69 |
* saved state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param portal A component portal which can be used to load the
|
|
Packit Service |
310c69 |
* specified component.
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef int (*Loader)(ReadPortal *portal);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Prototype for functions which can save an index component.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param component The index component.
|
|
Packit Service |
310c69 |
* @param writer A buffered writer.
|
|
Packit Service |
310c69 |
* @param zone The zone number.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef int (*Saver)(struct indexComponent *component,
|
|
Packit Service |
310c69 |
BufferedWriter *writer,
|
|
Packit Service |
310c69 |
unsigned int zone);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Command code used by IncrementalWriter function protocol.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef enum incrementalWriterCommand {
|
|
Packit Service |
310c69 |
IWC_START, //< start an incremental save
|
|
Packit Service |
310c69 |
IWC_CONTINUE, //< continue an incremental save
|
|
Packit Service |
310c69 |
IWC_FINISH, //< force finish of incremental save
|
|
Packit Service |
310c69 |
IWC_ABORT, //< abort incremental save
|
|
Packit Service |
310c69 |
IWC_IDLE = -1,//< not a command, used internally to signify not in progress
|
|
Packit Service |
310c69 |
IWC_DONE = -2 //< not a command, used internally to signify async completion
|
|
Packit Service |
310c69 |
} IncrementalWriterCommand;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct writeZone {
|
|
Packit Service |
310c69 |
struct indexComponent *component;
|
|
Packit Service |
310c69 |
IncrementalWriterCommand phase;
|
|
Packit Service |
310c69 |
BufferedWriter *writer;
|
|
Packit Service |
310c69 |
unsigned int zone;
|
|
Packit Service |
310c69 |
} WriteZone;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* @param [in] component The index component.
|
|
Packit Service |
310c69 |
* @param [in] writer A buffered writer.
|
|
Packit Service |
310c69 |
* @param [in] zone The zone number (0 for non-multi-zone).
|
|
Packit Service |
310c69 |
* @param [in] command The incremental writer command.
|
|
Packit Service |
310c69 |
* @param [out] completed If non-NULL, set to whether save is done.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef int (*IncrementalWriter)(struct indexComponent *component,
|
|
Packit Service |
310c69 |
BufferedWriter *writer,
|
|
Packit Service |
310c69 |
unsigned int zone,
|
|
Packit Service |
310c69 |
IncrementalWriterCommand command,
|
|
Packit Service |
310c69 |
bool *completed);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The structure describing how to load or save an index component.
|
|
Packit Service |
310c69 |
* At least one of saver or incremental must be specified.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef struct indexComponentInfo {
|
|
Packit Service |
310c69 |
RegionKind kind; // Region kind
|
|
Packit Service |
310c69 |
const char *name; // The name of the component (for logging)
|
|
Packit Service |
310c69 |
bool saveOnly; // Used for saves but not checkpoints
|
|
Packit Service |
310c69 |
bool chapterSync; // Saved by the chapter writer
|
|
Packit Service |
310c69 |
bool multiZone; // Does this component have multiple zones?
|
|
Packit Service |
310c69 |
bool ioStorage; // Do we do I/O directly to storage?
|
|
Packit Service |
310c69 |
Loader loader; // The function load this component
|
|
Packit Service |
310c69 |
Saver saver; // The function to store this component
|
|
Packit Service |
310c69 |
IncrementalWriter incremental; // The function for incremental writing
|
|
Packit Service |
310c69 |
} IndexComponentInfo;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The structure representing a savable (and loadable) part of an index.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef struct indexComponent {
|
|
Packit Service |
310c69 |
const IndexComponentInfo *info; // IndexComponentInfo specification
|
|
Packit Service |
310c69 |
void *componentData; // The object to load or save
|
|
Packit Service |
310c69 |
void *context; // The context used to load or save
|
|
Packit Service |
310c69 |
struct indexState *state; // The index state
|
|
Packit Service |
310c69 |
unsigned int numZones; // Number of zones in write portal
|
|
Packit Service |
310c69 |
WriteZone **writeZones; // State for writing component
|
|
Packit Service |
310c69 |
} IndexComponent;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Make an index component
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param state The index state in which this component instance
|
|
Packit Service |
310c69 |
* shall reside.
|
|
Packit Service |
310c69 |
* @param info The component info specification for this component.
|
|
Packit Service |
310c69 |
* @param zoneCount How many active zones are in use.
|
|
Packit Service |
310c69 |
* @param data Component-specific data.
|
|
Packit Service |
310c69 |
* @param context Component-specific context.
|
|
Packit Service |
310c69 |
* @param componentPtr Where to store the resulting component.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeIndexComponent(struct indexState *state,
|
|
Packit Service |
310c69 |
const IndexComponentInfo *info,
|
|
Packit Service |
310c69 |
unsigned int zoneCount,
|
|
Packit Service |
310c69 |
void *data,
|
|
Packit Service |
310c69 |
void *context,
|
|
Packit Service |
310c69 |
IndexComponent **componentPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Destroy and index component.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param componentPtr A pointer to the component to be freed.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeIndexComponent(IndexComponent **componentPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Return the index component name for this component.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE const char *indexComponentName(IndexComponent *component)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return component->info->name;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Return the index component data for this component.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE void *indexComponentData(IndexComponent *component)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return component->componentData;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Return the index component context for this component.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE void *indexComponentContext(IndexComponent *component)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return component->context;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Determine whether this component may be skipped for a checkpoint.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param component the component,
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return whether the component may be skipped
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE bool skipIndexComponentOnCheckpoint(IndexComponent *component)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return component->info->saveOnly;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Determine whether actual saving during a checkpoint should be
|
|
Packit Service |
310c69 |
* invoked by the chapter writer thread.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE bool
|
|
Packit Service |
310c69 |
deferIndexComponentCheckpointToChapterWriter(IndexComponent *component)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return component->info->chapterSync;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Determine whether a replay is required if component is missing.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param component the component
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return whether the component is final (that is, contains shutdown state)
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE bool
|
|
Packit Service |
310c69 |
missingIndexComponentRequiresReplay(IndexComponent *component)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return component->info->saveOnly;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Read a component's state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param component The component to read.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS, an error code from reading, or UDS_INVALID_ARGUMENT
|
|
Packit Service |
310c69 |
* if the component is NULL.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int readIndexComponent(IndexComponent *component)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Write a state file.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param component The component to write
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS, an error code from writing, or UDS_INVALID_ARGUMENT
|
|
Packit Service |
310c69 |
* if the component is NULL.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int writeIndexComponent(IndexComponent *component)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Start an incremental save for this component (all zones).
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] component The index component.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int startIndexComponentIncrementalSave(IndexComponent *component)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Perform an incremental save for a component in a particular zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] component The index component.
|
|
Packit Service |
310c69 |
* @param [in] zone The zone number.
|
|
Packit Service |
310c69 |
* @param [out] completed Pointer to hold completion status result.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @note If an incremental save is not supported, a regular
|
|
Packit Service |
310c69 |
* save will be performed if this is the first call in zone 0.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int performIndexComponentZoneSave(IndexComponent *component,
|
|
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 |
* Perform an incremental save for a non-multizone component synchronized
|
|
Packit Service |
310c69 |
* with the chapter writer.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param component The index component.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int performIndexComponentChapterWriterSave(IndexComponent *component)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Force the completion of an incremental save currently in progress in
|
|
Packit Service |
310c69 |
* a particular zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] component The index component.
|
|
Packit Service |
310c69 |
* @param [in] zone The zone number.
|
|
Packit Service |
310c69 |
* @param [out] completed Pointer to hold completion status result.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int finishIndexComponentZoneSave(IndexComponent *component,
|
|
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 save in all zones and complete
|
|
Packit Service |
310c69 |
* the overal save.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] component The index component.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @note If all zones call finishIndexComponentZoneSave first, only
|
|
Packit Service |
310c69 |
* the common non-index-related completion code is required,
|
|
Packit Service |
310c69 |
* which protects access to the index data structures from the
|
|
Packit Service |
310c69 |
* invoking thread.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int finishIndexComponentIncrementalSave(IndexComponent *component)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Abort the incremental save currently in progress in a particular zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] component The index component.
|
|
Packit Service |
310c69 |
* @param [in] zone The zone number.
|
|
Packit Service |
310c69 |
* @param [out] completed Pointer to hold completion status result.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @note "Completed" in this case means completed or aborted.
|
|
Packit Service |
310c69 |
* Once any zone calls this function the entire save is
|
|
Packit Service |
310c69 |
* useless unless every zone indicates CS_COMPLETED_PREVIOUSLY.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int abortIndexComponentZoneSave(IndexComponent *component,
|
|
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 |
* Abort an incremental save currently in progress
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] component The index component.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @note If all zones call abortIndexComponentZoneSave first, only
|
|
Packit Service |
310c69 |
* the common non-index-related completion code is required,
|
|
Packit Service |
310c69 |
* which protects access to the index data structures from the
|
|
Packit Service |
310c69 |
* invoking thread.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int abortIndexComponentIncrementalSave(IndexComponent *component)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Remove or invalidate component state.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param component The component whose file is to be removed. If NULL
|
|
Packit Service |
310c69 |
* no action is taken.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result))
|
|
Packit Service |
310c69 |
int discardIndexComponent(IndexComponent *component);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get a buffered reader for the specified component part.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] portal The component portal.
|
|
Packit Service |
310c69 |
* @param [in] part The component ordinal number.
|
|
Packit Service |
310c69 |
* @param [out] readerPtr Where to put the buffered reader.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @note the reader is managed by the component portal
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result))
|
|
Packit Service |
310c69 |
int getBufferedReaderForPortal(ReadPortal *portal,
|
|
Packit Service |
310c69 |
unsigned int part,
|
|
Packit Service |
310c69 |
BufferedReader **readerPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* INDEX_COMPONENT_H */
|