|
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/index.h#3 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef INDEX_H
|
|
Packit Service |
310c69 |
#define INDEX_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "chapterWriter.h"
|
|
Packit Service |
310c69 |
#include "indexLayout.h"
|
|
Packit Service |
310c69 |
#include "indexSession.h"
|
|
Packit Service |
310c69 |
#include "indexZone.h"
|
|
Packit Service |
310c69 |
#include "loadType.h"
|
|
Packit Service |
310c69 |
#include "masterIndexOps.h"
|
|
Packit Service |
310c69 |
#include "volume.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Index checkpoint state private to indexCheckpoint.c.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef struct indexCheckpoint IndexCheckpoint;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct index {
|
|
Packit Service |
310c69 |
bool existed;
|
|
Packit Service |
310c69 |
bool hasSavedOpenChapter;
|
|
Packit Service |
310c69 |
LoadType loadedType;
|
|
Packit Service |
310c69 |
IndexLoadContext *loadContext;
|
|
Packit Service |
310c69 |
IndexLayout *layout;
|
|
Packit Service |
310c69 |
IndexState *state;
|
|
Packit Service |
310c69 |
MasterIndex *masterIndex;
|
|
Packit Service |
310c69 |
Volume *volume;
|
|
Packit Service |
310c69 |
unsigned int zoneCount;
|
|
Packit Service |
310c69 |
IndexZone **zones;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* ATTENTION!!!
|
|
Packit Service |
310c69 |
* The meaning of the next two fields has changed.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* They now represent the oldest and newest chapters only at load time,
|
|
Packit Service |
310c69 |
* and when the index is quiescent. At other times, they may lag individual
|
|
Packit Service |
310c69 |
* zones' views of the index depending upon the progress made by the chapter
|
|
Packit Service |
310c69 |
* writer.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
uint64_t oldestVirtualChapter;
|
|
Packit Service |
310c69 |
uint64_t newestVirtualChapter;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
uint64_t lastCheckpoint;
|
|
Packit Service |
310c69 |
uint64_t prevCheckpoint;
|
|
Packit Service |
310c69 |
ChapterWriter *chapterWriter;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
// checkpoint state used by indexCheckpoint.c
|
|
Packit Service |
310c69 |
IndexCheckpoint *checkpoint;
|
|
Packit Service |
310c69 |
} Index;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Construct a new index from the given configuration.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layout The index layout
|
|
Packit Service |
310c69 |
* @param config The configuration to use
|
|
Packit Service |
310c69 |
* @param userParams The index session parameters. If NULL, the default
|
|
Packit Service |
310c69 |
* session parameters will be used.
|
|
Packit Service |
310c69 |
* @param zoneCount The number of zones for this index to use
|
|
Packit Service |
310c69 |
* @param loadType How to create the index: it can be create only, allow
|
|
Packit Service |
310c69 |
* loading from files, and allow rebuilding from the volume
|
|
Packit Service |
310c69 |
* @param loadContext The load context to use
|
|
Packit Service |
310c69 |
* @param newIndex A pointer to hold a pointer to the new index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeIndex(IndexLayout *layout,
|
|
Packit Service |
310c69 |
const Configuration *config,
|
|
Packit Service |
310c69 |
const struct uds_parameters *userParams,
|
|
Packit Service |
310c69 |
unsigned int zoneCount,
|
|
Packit Service |
310c69 |
LoadType loadType,
|
|
Packit Service |
310c69 |
IndexLoadContext *loadContext,
|
|
Packit Service |
310c69 |
Index **newIndex)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Save an index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* Before saving an index and while saving an index, the caller must ensure
|
|
Packit Service |
310c69 |
* that there are no index requests in progress.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* Some users follow saveIndex immediately with a freeIndex. But some tests
|
|
Packit Service |
310c69 |
* use the IndexLayout to modify the saved index. The Index will then have
|
|
Packit Service |
310c69 |
* some cached information that does not reflect these updates.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index The index to save
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS if successful
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int saveIndex(Index *index) __attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Clean up the index and its memory.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index The index to destroy.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeIndex(Index *index);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Perform the index operation specified by the action field of a UDS request.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* For UDS API requests, this searches the index for the chunk name in the
|
|
Packit Service |
310c69 |
* request. If the chunk name is already present in the index, the location
|
|
Packit Service |
310c69 |
* field of the request will be set to the IndexRegion where it was found. If
|
|
Packit Service |
310c69 |
* the action is not DELETE, the oldMetadata field of the request will also be
|
|
Packit Service |
310c69 |
* filled in with the prior metadata for the name.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* If the API request action is:
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* REQUEST_INDEX, a record will be added to the open chapter with the
|
|
Packit Service |
310c69 |
* metadata in the request for new records, and the existing metadata for
|
|
Packit Service |
310c69 |
* existing records
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* REQUEST_UPDATE, a record will be added to the open chapter with the
|
|
Packit Service |
310c69 |
* metadata in the request
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* REQUEST_QUERY, if the update flag is set in the request, any record
|
|
Packit Service |
310c69 |
* found will be moved to the open chapter. In all other cases the contents
|
|
Packit Service |
310c69 |
* of the index will remain unchanged.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* REQUEST_REMOVE, the any entry with the name will removed from the index
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* For non-API requests, no chunk name search is involved.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index The index
|
|
Packit Service |
310c69 |
* @param request The originating request
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS, UDS_QUEUED, or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int dispatchIndexRequest(Index *index, Request *request)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Internal helper to prepare the index for saving.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index the index
|
|
Packit Service |
310c69 |
* @param checkpoint whether the save is a checkpoint
|
|
Packit Service |
310c69 |
* @param openChapterNumber the virtual chapter number of the open chapter
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void beginSave(Index *index, bool checkpoint, uint64_t openChapterNumber);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Replay the volume file to repopulate the master index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index The index
|
|
Packit Service |
310c69 |
* @param fromVCN The virtual chapter to start replaying
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS if successful
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int replayVolume(Index *index, uint64_t fromVCN)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Gather statistics from the master index, volume, and cache.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index The index
|
|
Packit Service |
310c69 |
* @param counters the statistic counters for the index
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void getIndexStats(Index *index, UdsIndexStats *counters);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Set lookup state for this index. Disabling lookups means assume
|
|
Packit Service |
310c69 |
* all records queried are new (intended for debugging uses, e.g.,
|
|
Packit Service |
310c69 |
* albfill).
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index The index
|
|
Packit Service |
310c69 |
* @param enabled The new lookup state
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void setIndexLookupState(Index *index, bool enabled);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Advance the newest virtual chapter. If this will overwrite the oldest
|
|
Packit Service |
310c69 |
* virtual chapter, advance that also.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index The index to advance
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void advanceActiveChapters(Index *index);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Triage an index request, deciding whether it requires that a sparse cache
|
|
Packit Service |
310c69 |
* barrier message precede it.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This resolves the chunk name in the request in the master index,
|
|
Packit Service |
310c69 |
* determining if it is a hook or not, and if a hook, what virtual chapter (if
|
|
Packit Service |
310c69 |
* any) it might be found in. If a virtual chapter is found, it checks whether
|
|
Packit Service |
310c69 |
* that chapter appears in the sparse region of the index. If all these
|
|
Packit Service |
310c69 |
* conditions are met, the (sparse) virtual chapter number is returned. In all
|
|
Packit Service |
310c69 |
* other cases it returns UINT64_MAX .
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param index the index that will process the request
|
|
Packit Service |
310c69 |
* @param request the index request containing the chunk name to triage
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the sparse chapter number for the sparse cache barrier message, or
|
|
Packit Service |
310c69 |
* UINT64_MAX if the request does not require a barrier
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
uint64_t triageIndexRequest(Index *index, Request *request)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* INDEX_H */
|