|
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/indexSession.h#6 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef INDEX_SESSION_H
|
|
Packit Service |
310c69 |
#define INDEX_SESSION_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "atomicDefs.h"
|
|
Packit Service |
310c69 |
#include "config.h"
|
|
Packit Service |
310c69 |
#include "cpu.h"
|
|
Packit Service |
310c69 |
#include "opaqueTypes.h"
|
|
Packit Service |
310c69 |
#include "threads.h"
|
|
Packit Service |
310c69 |
#include "uds.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The bit position of flags used to indicate index session states.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef enum {
|
|
Packit Service |
310c69 |
IS_FLAG_BIT_START = 8,
|
|
Packit Service |
310c69 |
/** Flag indicating that the session is loading */
|
|
Packit Service |
310c69 |
IS_FLAG_BIT_LOADING = IS_FLAG_BIT_START,
|
|
Packit Service |
310c69 |
/** Flag indicating that that the session has been loaded */
|
|
Packit Service |
310c69 |
IS_FLAG_BIT_LOADED,
|
|
Packit Service |
310c69 |
/** Flag indicating that the session is disabled permanently */
|
|
Packit Service |
310c69 |
IS_FLAG_BIT_DISABLED,
|
|
Packit Service |
310c69 |
/** Flag indicating that the session is suspended */
|
|
Packit Service |
310c69 |
IS_FLAG_BIT_SUSPENDED,
|
|
Packit Service |
310c69 |
/** Flag indicating that the session is waiting for an index state change */
|
|
Packit Service |
310c69 |
IS_FLAG_BIT_WAITING,
|
|
Packit Service |
310c69 |
/** Flag indicating that that the session is closing */
|
|
Packit Service |
310c69 |
IS_FLAG_BIT_CLOSING,
|
|
Packit Service |
310c69 |
/** Flag indicating that that the session is being destroyed */
|
|
Packit Service |
310c69 |
IS_FLAG_BIT_DESTROYING,
|
|
Packit Service |
310c69 |
} IndexSessionFlagBit;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The index session state flags.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef enum {
|
|
Packit Service |
310c69 |
IS_FLAG_LOADED = (1 << IS_FLAG_BIT_LOADED),
|
|
Packit Service |
310c69 |
IS_FLAG_LOADING = (1 << IS_FLAG_BIT_LOADING),
|
|
Packit Service |
310c69 |
IS_FLAG_DISABLED = (1 << IS_FLAG_BIT_DISABLED),
|
|
Packit Service |
310c69 |
IS_FLAG_SUSPENDED = (1 << IS_FLAG_BIT_SUSPENDED),
|
|
Packit Service |
310c69 |
IS_FLAG_WAITING = (1 << IS_FLAG_BIT_WAITING),
|
|
Packit Service |
310c69 |
IS_FLAG_CLOSING = (1 << IS_FLAG_BIT_CLOSING),
|
|
Packit Service |
310c69 |
IS_FLAG_DESTROYING = (1 << IS_FLAG_BIT_DESTROYING),
|
|
Packit Service |
310c69 |
} IndexSessionFlag;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct __attribute__((aligned(CACHE_LINE_BYTES))) sessionStats {
|
|
Packit Service |
310c69 |
uint64_t postsFound; /* Post calls that found an entry */
|
|
Packit Service |
310c69 |
uint64_t postsFoundOpenChapter; /* Post calls found in the open chapter */
|
|
Packit Service |
310c69 |
uint64_t postsFoundDense; /* Post calls found in the dense index */
|
|
Packit Service |
310c69 |
uint64_t postsFoundSparse; /* Post calls found in the sparse index */
|
|
Packit Service |
310c69 |
uint64_t postsNotFound; /* Post calls that did not find an entry */
|
|
Packit Service |
310c69 |
uint64_t updatesFound; /* Update calls that found an entry */
|
|
Packit Service |
310c69 |
uint64_t updatesNotFound; /* Update calls that did not find an entry */
|
|
Packit Service |
310c69 |
uint64_t deletionsFound; /* Delete calls that found an entry */
|
|
Packit Service |
310c69 |
uint64_t deletionsNotFound; /* Delete calls that did not find an entry */
|
|
Packit Service |
310c69 |
uint64_t queriesFound; /* Query calls that found an entry */
|
|
Packit Service |
310c69 |
uint64_t queriesNotFound; /* Query calls that did not find an entry */
|
|
Packit Service |
310c69 |
uint64_t requests; /* Total number of requests */
|
|
Packit Service |
310c69 |
} SessionStats;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* States used in the index load context, reflecting the state of the index.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef enum {
|
|
Packit Service |
310c69 |
/** The index has not been loaded or rebuilt completely */
|
|
Packit Service |
310c69 |
INDEX_OPENING = 0,
|
|
Packit Service |
310c69 |
/** The index is able to handle requests */
|
|
Packit Service |
310c69 |
INDEX_READY,
|
|
Packit Service |
310c69 |
/** The index has a pending request to suspend */
|
|
Packit Service |
310c69 |
INDEX_SUSPENDING,
|
|
Packit Service |
310c69 |
/** The index is suspended in the midst of a rebuild */
|
|
Packit Service |
310c69 |
INDEX_SUSPENDED,
|
|
Packit Service |
310c69 |
/** The index is being shut down while suspended */
|
|
Packit Service |
310c69 |
INDEX_FREEING,
|
|
Packit Service |
310c69 |
} IndexSuspendStatus;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The CondVar here must be notified when the status changes to
|
|
Packit Service |
310c69 |
* INDEX_SUSPENDED, in order to wake up the waiting udsSuspendIndexSession()
|
|
Packit Service |
310c69 |
* call. It must also be notified when the status changes away from
|
|
Packit Service |
310c69 |
* INDEX_SUSPENDED, to resume rebuild the index from checkForSuspend() in the
|
|
Packit Service |
310c69 |
* index.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef struct indexLoadContext {
|
|
Packit Service |
310c69 |
Mutex mutex;
|
|
Packit Service |
310c69 |
CondVar cond;
|
|
Packit Service |
310c69 |
IndexSuspendStatus status; // Covered by indexLoadContext.mutex.
|
|
Packit Service |
310c69 |
} IndexLoadContext;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* The request CondVar here must be notified when IS_FLAG_WAITING is cleared,
|
|
Packit Service |
310c69 |
* in case udsCloseIndex() or udsDestroyIndexSession() is waiting on that flag.
|
|
Packit Service |
310c69 |
* It must also be notified when IS_FLAG_CLOSING is cleared, in case
|
|
Packit Service |
310c69 |
* udsSuspendIndexSession(), udsCloseIndex() or udsDestroyIndexSession() is
|
|
Packit Service |
310c69 |
* waiting on that flag.
|
|
Packit Service |
310c69 |
* Finally, it must also be notified when IS_FLAG_LOADING is cleared, to inform
|
|
Packit Service |
310c69 |
* udsDestroyIndexSession() that the index session can be safely freed.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
struct uds_index_session {
|
|
Packit Service |
310c69 |
unsigned int state; // Covered by requestMutex.
|
|
Packit Service |
310c69 |
IndexRouter *router;
|
|
Packit Service |
310c69 |
RequestQueue *callbackQueue;
|
|
Packit Service |
310c69 |
struct udsConfiguration userConfig;
|
|
Packit Service |
310c69 |
IndexLoadContext loadContext;
|
|
Packit Service |
310c69 |
// Asynchronous Request synchronization
|
|
Packit Service |
310c69 |
Mutex requestMutex;
|
|
Packit Service |
310c69 |
CondVar requestCond;
|
|
Packit Service |
310c69 |
int requestCount;
|
|
Packit Service |
310c69 |
// Request statistics, all owned by the callback thread
|
|
Packit Service |
310c69 |
SessionStats stats;
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Check that the index session is usable.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSession the session to query
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int checkIndexSession(struct uds_index_session *indexSession)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Make sure that the IndexSession is allowed to load an index, and if so, set
|
|
Packit Service |
310c69 |
* its state to indicate that the load has started.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSession the session to load with
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS, or an error code if an index already exists.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int startLoadingIndexSession(struct uds_index_session *indexSession)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Update the IndexSession state after attempting to load an index, to indicate
|
|
Packit Service |
310c69 |
* that the load has completed, and whether or not it succeeded.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSession the session that was loading
|
|
Packit Service |
310c69 |
* @param result the result of the load operation
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void finishLoadingIndexSession(struct uds_index_session *indexSession,
|
|
Packit Service |
310c69 |
int result);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Disable an index session due to an error.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSession the session to be disabled
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void disableIndexSession(struct uds_index_session *indexSession);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Acquire the index session for an asynchronous index request.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* The pointer must eventually be released with a corresponding call to
|
|
Packit Service |
310c69 |
* releaseIndexSession().
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSession The index session
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int getIndexSession(struct uds_index_session *indexSession)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Release a pointer to an index session.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSession The session to release
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void releaseIndexSession(struct uds_index_session *indexSession);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Construct a new, empty index session.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSessionPtr The pointer to receive the new session
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeEmptyIndexSession(struct uds_index_session **indexSessionPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Save an index while the session is quiescent.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* During the call to #udsSaveIndex, there should be no other call to
|
|
Packit Service |
310c69 |
* #udsSaveIndex and there should be no calls to #udsStartChunkOperation.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSession The session to save
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return Either #UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int udsSaveIndex(struct uds_index_session *indexSession)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Close the index by saving the underlying index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param indexSession The index session to be shut down and freed
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int saveAndFreeIndex(struct uds_index_session *indexSession);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Set the checkpoint frequency of the grid.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param session The index session to be modified.
|
|
Packit Service |
310c69 |
* @param frequency New checkpoint frequency.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return Either UDS_SUCCESS or an error code.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int udsSetCheckpointFrequency(struct uds_index_session *session,
|
|
Packit Service |
310c69 |
unsigned int frequency)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* INDEX_SESSION_H */
|