|
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/indexInternals.c#7 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "indexInternals.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "errors.h"
|
|
Packit Service |
310c69 |
#include "indexCheckpoint.h"
|
|
Packit Service |
310c69 |
#include "indexStateData.h"
|
|
Packit Service |
310c69 |
#include "indexZone.h"
|
|
Packit Service |
310c69 |
#include "logger.h"
|
|
Packit Service |
310c69 |
#include "memoryAlloc.h"
|
|
Packit Service |
310c69 |
#include "openChapter.h"
|
|
Packit Service |
310c69 |
#include "request.h"
|
|
Packit Service |
310c69 |
#include "stringUtils.h"
|
|
Packit Service |
310c69 |
#include "threads.h"
|
|
Packit Service |
310c69 |
#include "typeDefs.h"
|
|
Packit Service |
310c69 |
#include "volume.h"
|
|
Packit Service |
310c69 |
#include "zone.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
static const unsigned int MAX_COMPONENT_COUNT = 4;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int allocateIndex(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 |
Index **newIndex)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
unsigned int checkpoint_frequency
|
|
Packit Service |
310c69 |
= userParams == NULL ? 0 : userParams->checkpoint_frequency;
|
|
Packit Service |
310c69 |
if (checkpoint_frequency >= config->geometry->chaptersPerVolume) {
|
|
Packit Service |
310c69 |
return UDS_BAD_CHECKPOINT_FREQUENCY;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
Index *index;
|
|
Packit Service |
310c69 |
int result = ALLOCATE(1, Index, "index", &index);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
index->existed = (loadType != LOAD_CREATE);
|
|
Packit Service |
310c69 |
index->hasSavedOpenChapter = true;
|
|
Packit Service |
310c69 |
index->loadedType = LOAD_UNDEFINED;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
result = makeIndexCheckpoint(index);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
freeIndex(index);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
setIndexCheckpointFrequency(index->checkpoint, checkpoint_frequency);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
getIndexLayout(layout, &index->layout);
|
|
Packit Service |
310c69 |
index->zoneCount = zoneCount;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
result = ALLOCATE(index->zoneCount, IndexZone *, "zones",
|
|
Packit Service |
310c69 |
&index->zones);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
freeIndex(index);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
result = makeIndexState(layout, index->zoneCount, MAX_COMPONENT_COUNT,
|
|
Packit Service |
310c69 |
&index->state);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
freeIndex(index);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
result = addIndexStateComponent(index->state, &INDEX_STATE_INFO, index,
|
|
Packit Service |
310c69 |
NULL);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
freeIndex(index);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
result = makeVolume(config, index->layout, userParams,
|
|
Packit Service |
310c69 |
VOLUME_CACHE_DEFAULT_MAX_QUEUED_READS, index->zoneCount,
|
|
Packit Service |
310c69 |
&index->volume);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
freeIndex(index);
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
index->volume->lookupMode = LOOKUP_NORMAL;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < index->zoneCount; i++) {
|
|
Packit Service |
310c69 |
result = makeIndexZone(index, i);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
freeIndex(index);
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result, "Could not create index zone");
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
result = addIndexStateComponent(index->state, &OPEN_CHAPTER_INFO, index,
|
|
Packit Service |
310c69 |
NULL);
|
|
Packit Service |
310c69 |
if (result != UDS_SUCCESS) {
|
|
Packit Service |
310c69 |
freeIndex(index);
|
|
Packit Service |
310c69 |
return logErrorWithStringError(result, "Could not create open chapter");
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
*newIndex = index;
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
void releaseIndex(Index *index)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
if (index == NULL) {
|
|
Packit Service |
310c69 |
return;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
if (index->zones != NULL) {
|
|
Packit Service |
310c69 |
unsigned int i;
|
|
Packit Service |
310c69 |
for (i = 0; i < index->zoneCount; i++) {
|
|
Packit Service |
310c69 |
freeIndexZone(index->zones[i]);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
FREE(index->zones);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
freeVolume(index->volume);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
freeIndexState(&index->state);
|
|
Packit Service |
310c69 |
freeIndexCheckpoint(index->checkpoint);
|
|
Packit Service |
310c69 |
putIndexLayout(&index->layout);
|
|
Packit Service |
310c69 |
FREE(index);
|
|
Packit Service |
310c69 |
}
|