Blame source/uds/index.h

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