mirror of https://gitee.com/bigwinds/arangodb
270 lines
11 KiB
C
270 lines
11 KiB
C
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief shadow data storage
|
|
///
|
|
/// @file
|
|
///
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2011-2012 triagens GmbH, Cologne, Germany
|
|
///
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
/// you may not use this file except in compliance with the License.
|
|
/// You may obtain a copy of the License at
|
|
///
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
///
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
/// See the License for the specific language governing permissions and
|
|
/// limitations under the License.
|
|
///
|
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
|
///
|
|
/// @author Dr. Frank Celler
|
|
/// @author Copyright 2012, triagens GmbH, Cologne, Germany
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef TRIAGENS_DURHAM_VOC_BASE_SHADOW_DATA_H
|
|
#define TRIAGENS_DURHAM_VOC_BASE_SHADOW_DATA_H 1
|
|
|
|
#include <BasicsC/common.h>
|
|
#include <BasicsC/locks.h>
|
|
#include <BasicsC/associative.h>
|
|
|
|
#include "VocBase/vocbase.h"
|
|
#include "VocBase/document-collection.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- DEFINES
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup VocBase
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief delete at most this number of shadows during a gc cycle
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define SHADOW_MAX_DELETE 20
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- SHADOW DATA
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- public types
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup VocBase
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief typedef for shadow ids
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef TRI_voc_tick_t TRI_shadow_id;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief shadow data (base struct)
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct TRI_shadow_s {
|
|
TRI_shadow_id _id;
|
|
int64_t _rc; // refcount
|
|
double _timestamp; // creation timestamp
|
|
void* _data;
|
|
}
|
|
TRI_shadow_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief shadow data storage
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct TRI_shadow_store_s {
|
|
TRI_mutex_t _lock;
|
|
TRI_associative_pointer_t _index;
|
|
|
|
void (*destroyShadow) (struct TRI_shadow_store_s*, TRI_shadow_t*);
|
|
}
|
|
TRI_shadow_store_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- constructors and destructors
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup VocBase
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief creates a shadow data storage
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
TRI_shadow_store_t* TRI_CreateShadowStore (void (*destroy) (TRI_shadow_store_t*, TRI_shadow_t*));
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief destroys a shadow data storage
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_FreeShadowStore (TRI_shadow_store_t* const store);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- public methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup VocBase
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief enumerate all shadows and remove them if expired
|
|
///
|
|
/// The max age must be specified in seconds
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_CleanupShadowData (TRI_shadow_store_t* const, const double);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief looks up shadow data
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
TRI_shadow_t* TRI_FindShadowData (TRI_shadow_store_t* const, const TRI_shadow_id);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief stores shadow data
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
TRI_shadow_t* TRI_StoreShadowData (TRI_shadow_store_t* const,
|
|
const void* const);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief releases shadow data
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool TRI_ReleaseShadowData (TRI_shadow_store_t* const, TRI_shadow_t*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- SHADOW DOCUMENTS
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- constructors and destructors
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup VocBase
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief shadow document
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct TRI_shadow_document_s {
|
|
TRI_shadow_t* _base;
|
|
|
|
TRI_voc_cid_t _cid;
|
|
TRI_voc_did_t _did;
|
|
TRI_voc_rid_t _rid;
|
|
}
|
|
TRI_shadow_document_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief shadow document storage
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct TRI_shadow_document_store_s {
|
|
TRI_shadow_store_t* _base;
|
|
|
|
void* (*createShadow) (struct TRI_shadow_document_store_s*, struct TRI_doc_collection_s*, struct TRI_doc_mptr_s const*);
|
|
bool (*verifyShadow) (struct TRI_shadow_document_store_s*, struct TRI_doc_collection_s*, struct TRI_doc_mptr_s const*, void*);
|
|
void (*destroyShadow) (struct TRI_shadow_document_store_s*, TRI_shadow_document_t*);
|
|
}
|
|
TRI_shadow_document_store_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief initialises a shadow document storage
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
TRI_shadow_document_store_t* TRI_CreateShadowDocumentStore (
|
|
void* (*create) (TRI_shadow_document_store_t*, TRI_doc_collection_t*, TRI_doc_mptr_t const*),
|
|
bool (*verify) (TRI_shadow_document_store_t*, TRI_doc_collection_t*, TRI_doc_mptr_t const*, void*),
|
|
void (*destroy) (TRI_shadow_document_store_t*, TRI_shadow_document_t*));
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief destroys a shadow document storage
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_FreeShadowDocumentStore (TRI_shadow_document_store_t* const);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- public methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup VocBase
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief looks up or creates a shadow document
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
TRI_shadow_document_t* TRI_FindShadowDocument (TRI_shadow_document_store_t* const,
|
|
TRI_vocbase_t*,
|
|
TRI_voc_cid_t,
|
|
TRI_voc_did_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief releases a shadow document
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool TRI_ReleaseShadowDocument (TRI_shadow_document_store_t* const,
|
|
TRI_shadow_document_t*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
// Local Variables:
|
|
// mode: outline-minor
|
|
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
|
// End:
|