|
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/indexStateData.c#3 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "indexStateData.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "buffer.h"
|
|
Packit Service |
310c69 |
#include "errors.h"
|
|
Packit Service |
310c69 |
#include "index.h"
|
|
Packit Service |
310c69 |
#include "logger.h"
|
|
Packit Service |
310c69 |
#include "uds.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/* The index state version header */
|
|
Packit Service |
310c69 |
typedef struct {
|
|
Packit Service |
310c69 |
int32_t signature;
|
|
Packit Service |
310c69 |
int32_t versionID;
|
|
Packit Service |
310c69 |
} IndexStateVersion;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/* The version 301 index state */
|
|
Packit Service |
310c69 |
typedef struct {
|
|
Packit Service |
310c69 |
uint64_t newestChapter;
|
|
Packit Service |
310c69 |
uint64_t oldestChapter;
|
|
Packit Service |
310c69 |
uint64_t lastCheckpoint;
|
|
Packit Service |
310c69 |
uint32_t unused;
|
|
Packit Service |
310c69 |
uint32_t padding;
|
|
Packit Service |
310c69 |
} IndexStateData301;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
static const IndexStateVersion INDEX_STATE_VERSION_301 = {
|
|
Packit Service |
310c69 |
.signature = -1,
|
|
Packit Service |
310c69 |
.versionID = 301,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The index state index component reader.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param portal the ReadPortal that handles the read of the component
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static int readIndexStateData(ReadPortal *portal)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
Buffer *buffer = getStateIndexStateBuffer(portal->component->state, IO_READ);
|
|
Packit Service |
310c69 |
int result = rewindBuffer(buffer, uncompactedAmount(buffer));
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
IndexStateVersion fileVersion;
|
|
Packit Service |
310c69 |
result = getInt32LEFromBuffer(buffer, &fileVersion.signature);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = getInt32LEFromBuffer(buffer, &fileVersion.versionID);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
if (fileVersion.signature != -1 || fileVersion.versionID != 301) {
|
|
Packit Service |
310c69 |
return logErrorWithStringError(UDS_UNSUPPORTED_VERSION,
|
|
Packit Service |
310c69 |
"Index state version %d,%d is unsupported",
|
|
Packit Service |
310c69 |
fileVersion.signature,
|
|
Packit Service |
310c69 |
fileVersion.versionID);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
IndexStateData301 state;
|
|
Packit Service |
310c69 |
result = getUInt64LEFromBuffer(buffer, &state.newestChapter);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = getUInt64LEFromBuffer(buffer, &state.oldestChapter);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = getUInt64LEFromBuffer(buffer, &state.lastCheckpoint);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = getUInt32LEFromBuffer(buffer, &state.unused);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = getUInt32LEFromBuffer(buffer, &state.padding);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
if ((state.unused != 0) || (state.padding != 0)) {
|
|
Packit Service |
310c69 |
return UDS_CORRUPT_COMPONENT;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
Index *index = indexComponentData(portal->component);
|
|
Packit Service |
310c69 |
index->newestVirtualChapter = state.newestChapter;
|
|
Packit Service |
310c69 |
index->oldestVirtualChapter = state.oldestChapter;
|
|
Packit Service |
310c69 |
index->lastCheckpoint = state.lastCheckpoint;
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The index state index component writer.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param component The component whose state is to be saved (an Index)
|
|
Packit Service |
310c69 |
* @param writer The buffered writer.
|
|
Packit Service |
310c69 |
* @param zone The zone to write.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static int writeIndexStateData(IndexComponent *component,
|
|
Packit Service |
310c69 |
BufferedWriter *writer __attribute__((unused)),
|
|
Packit Service |
310c69 |
unsigned int zone __attribute__((unused)))
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
Buffer *buffer = getStateIndexStateBuffer(component->state, IO_WRITE);
|
|
Packit Service |
310c69 |
int result = resetBufferEnd(buffer, 0);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = putUInt32LEIntoBuffer(buffer, INDEX_STATE_VERSION_301.signature);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = putUInt32LEIntoBuffer(buffer, INDEX_STATE_VERSION_301.versionID);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
Index *index = indexComponentData(component);
|
|
Packit Service |
310c69 |
IndexStateData301 state = {
|
|
Packit Service |
310c69 |
.newestChapter = index->newestVirtualChapter,
|
|
Packit Service |
310c69 |
.oldestChapter = index->oldestVirtualChapter,
|
|
Packit Service |
310c69 |
.lastCheckpoint = index->lastCheckpoint,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
result = putUInt64LEIntoBuffer(buffer, state.newestChapter);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = putUInt64LEIntoBuffer(buffer, state.oldestChapter);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = putUInt64LEIntoBuffer(buffer, state.lastCheckpoint);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = putUInt32LEIntoBuffer(buffer, state.unused);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
result = putUInt32LEIntoBuffer(buffer, state.padding);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
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 |
|
|
Packit Service |
310c69 |
const IndexComponentInfo INDEX_STATE_INFO = {
|
|
Packit Service |
310c69 |
.kind = RL_KIND_INDEX_STATE,
|
|
Packit Service |
310c69 |
.name = "index state",
|
|
Packit Service |
310c69 |
.saveOnly = false,
|
|
Packit Service |
310c69 |
.chapterSync = true,
|
|
Packit Service |
310c69 |
.multiZone = false,
|
|
Packit Service |
310c69 |
.ioStorage = false,
|
|
Packit Service |
310c69 |
.loader = readIndexStateData,
|
|
Packit Service |
310c69 |
.saver = writeIndexStateData,
|
|
Packit Service |
310c69 |
.incremental = NULL,
|
|
Packit Service |
310c69 |
};
|