|
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/indexRouter.h#3 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef INDEX_ROUTER_H
|
|
Packit Service |
310c69 |
#define INDEX_ROUTER_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "compiler.h"
|
|
Packit Service |
310c69 |
#include "index.h"
|
|
Packit Service |
310c69 |
#include "indexSession.h"
|
|
Packit Service |
310c69 |
#include "request.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Callback after a query, update or remove request completes and fills in
|
|
Packit Service |
310c69 |
* select fields in the request: status for all requests, oldMetadata and
|
|
Packit Service |
310c69 |
* hashExists for query and update requests.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param request request object.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef void (*IndexRouterCallback)(Request *request);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
struct indexRouter {
|
|
Packit Service |
310c69 |
IndexRouterCallback callback;
|
|
Packit Service |
310c69 |
unsigned int zoneCount;
|
|
Packit Service |
310c69 |
bool needToSave;
|
|
Packit Service |
310c69 |
Index *index;
|
|
Packit Service |
310c69 |
RequestQueue *triageQueue;
|
|
Packit Service |
310c69 |
RequestQueue *zoneQueues[];
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Construct and initialize an IndexRouter instance.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layout the IndexLayout that describes the stored index
|
|
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 loadType selects whether to create, load, or rebuild the index
|
|
Packit Service |
310c69 |
* @param loadContext the index load context to use
|
|
Packit Service |
310c69 |
* @param callback the function to invoke when a request completes or fails
|
|
Packit Service |
310c69 |
* @param routerPtr a pointer in which to store the new router
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeIndexRouter(IndexLayout *layout,
|
|
Packit Service |
310c69 |
const Configuration *config,
|
|
Packit Service |
310c69 |
const struct uds_parameters *userParams,
|
|
Packit Service |
310c69 |
LoadType loadType,
|
|
Packit Service |
310c69 |
IndexLoadContext *loadContext,
|
|
Packit Service |
310c69 |
IndexRouterCallback callback,
|
|
Packit Service |
310c69 |
IndexRouter **routerPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Executes the index operation for a UDS request and calls the callback upon
|
|
Packit Service |
310c69 |
* completion.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param router The index router.
|
|
Packit Service |
310c69 |
* @param request A pointer to the Request to process.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void executeIndexRouterRequest(IndexRouter *router, Request *request);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Save the index router state to persistent storage.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* It is the responsibility of the caller to ensure that there are no other
|
|
Packit Service |
310c69 |
* uses of the index during a call to this method. It is necessary that there
|
|
Packit Service |
310c69 |
* be no index requests from any block context nor any other attempt to save
|
|
Packit Service |
310c69 |
* the index until after a call to saveIndexRouter returns.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param router the index router to save
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS if successful.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int saveIndexRouter(IndexRouter *router) __attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Destroy the index router and free its memory.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param router the index router to destroy (may be NULL)
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS if successful.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeIndexRouter(IndexRouter *router);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Select and return the request queue responsible for executing the next
|
|
Packit Service |
310c69 |
* index stage of a request, updating the request with any associated state
|
|
Packit Service |
310c69 |
* (such as the zone number for UDS requests on a local index).
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param router The index router.
|
|
Packit Service |
310c69 |
* @param request The Request destined for the queue.
|
|
Packit Service |
310c69 |
* @param nextStage The next request stage (STAGE_TRIAGE or STAGE_INDEX).
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the next index stage queue (the local triage queue, local zone
|
|
Packit Service |
310c69 |
* queue, or remote RPC send queue)
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
RequestQueue *selectIndexRouterQueue(IndexRouter *router,
|
|
Packit Service |
310c69 |
Request *request,
|
|
Packit Service |
310c69 |
RequestStage nextStage);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Wait for the index router to finish all operations that access a local
|
|
Packit Service |
310c69 |
* storage device.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param router The index router.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static INLINE void waitForIdleIndexRouter(IndexRouter *router)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
waitForIdleChapterWriter(router->index->chapterWriter);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* INDEX_ROUTER_H */
|