Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/wiredtiger_ext.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*-
0002  * Copyright (c) 2014-present MongoDB, Inc.
0003  * Copyright (c) 2008-2014 WiredTiger, Inc.
0004  *  All rights reserved.
0005  *
0006  * See the file LICENSE for redistribution information.
0007  */
0008 
0009 #ifndef __WIREDTIGER_EXT_H_
0010 #define __WIREDTIGER_EXT_H_
0011 
0012 #include <wiredtiger.h>
0013 
0014 #if defined(__cplusplus)
0015 extern "C" {
0016 #endif
0017 
0018 #if !defined(SWIG)
0019 
0020 /*!
0021  * @addtogroup wt_ext
0022  * @{
0023  */
0024 
0025 /*!
0026  * Read-committed isolation level, returned by
0027  * WT_EXTENSION_API::transaction_isolation_level.
0028  */
0029 #define WT_TXN_ISO_READ_COMMITTED 1
0030 /*!
0031  * Read-uncommitted isolation level, returned by
0032  * WT_EXTENSION_API::transaction_isolation_level.
0033  */
0034 #define WT_TXN_ISO_READ_UNCOMMITTED 2
0035 /*!
0036  * Snapshot isolation level, returned by
0037  * WT_EXTENSION_API::transaction_isolation_level.
0038  */
0039 #define WT_TXN_ISO_SNAPSHOT 3
0040 
0041 typedef struct __wt_txn_notify WT_TXN_NOTIFY;
0042 /*!
0043  * Snapshot isolation level, returned by
0044  * WT_EXTENSION_API::transaction_isolation_level.
0045  */
0046 struct __wt_txn_notify {
0047     /*!
0048      * A method called when the session's current transaction is committed
0049      * or rolled back.
0050      *
0051      * @param notify a pointer to the event handler
0052      * @param session the current session handle
0053      * @param txnid the transaction ID
0054      * @param committed an integer value which is non-zero if the
0055      * transaction is being committed.
0056      */
0057     int (*notify)(WT_TXN_NOTIFY *notify, WT_SESSION *session, uint64_t txnid, int committed);
0058 };
0059 
0060 /*!
0061  * Table of WiredTiger extension methods.
0062  *
0063  * This structure is used to provide a set of WiredTiger methods to extension
0064  * modules without needing to link the modules with the WiredTiger library.
0065  *
0066  * The extension methods may be used both by modules that are linked with
0067  * the WiredTiger library (for example, a data source configured using the
0068  * WT_CONNECTION::add_data_source method), and by modules not linked with the
0069  * WiredTiger library (for example, a compression module configured using the
0070  * WT_CONNECTION::add_compressor method).
0071  *
0072  * To use these functions:
0073  * - include the wiredtiger_ext.h header file,
0074  * - declare a variable which references a WT_EXTENSION_API structure, and
0075  * - initialize the variable using WT_CONNECTION::get_extension_api method.
0076  *
0077  * @snippet ex_data_source.c WT_EXTENSION_API declaration
0078  *
0079  * The following code is from the sample compression module, where compression
0080  * extension functions are configured in the extension's entry point:
0081  *
0082  * @snippet nop_compress.c WT_COMPRESSOR initialization structure
0083  * @snippet nop_compress.c WT_COMPRESSOR initialization function
0084  */
0085 struct __wt_extension_api {
0086 /* !!! To maintain backwards compatibility, this structure is append-only. */
0087 #if !defined(DOXYGEN)
0088     /*
0089      * Private fields.
0090      */
0091     WT_CONNECTION *conn; /* Enclosing connection */
0092 #endif
0093     /*!
0094      * Insert an error message into the WiredTiger error stream.
0095      *
0096      * @param wt_api the extension handle
0097      * @param session the session handle (or NULL if none available)
0098      * @param fmt a printf-like format specification
0099      * @errors
0100      *
0101      * @snippet ex_data_source.c WT_EXTENSION_API err_printf
0102      */
0103     int (*err_printf)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *fmt, ...);
0104 
0105     /*!
0106      * Insert a message into the WiredTiger message stream.
0107      *
0108      * @param wt_api the extension handle
0109      * @param session the session handle (or NULL if none available)
0110      * @param fmt a printf-like format specification
0111      * @errors
0112      *
0113      * @snippet ex_data_source.c WT_EXTENSION_API msg_printf
0114      */
0115     int (*msg_printf)(WT_EXTENSION_API *, WT_SESSION *session, const char *fmt, ...);
0116 
0117     /*!
0118      * Return information about an error as a string.
0119      *
0120      * @snippet ex_data_source.c WT_EXTENSION_API strerror
0121      *
0122      * @param wt_api the extension handle
0123      * @param session the session handle (or NULL if none available)
0124      * @param error a return value from a WiredTiger function
0125      * @returns a string representation of the error
0126      */
0127     const char *(*strerror)(WT_EXTENSION_API *, WT_SESSION *session, int error);
0128 
0129     /*!
0130      * Map a Windows system error code to a POSIX 1003.1/ANSI C error.
0131      *
0132      * @param wt_api the extension handle
0133      * @param session the session handle (or NULL if none available)
0134      * @param windows_error a Windows system error code
0135      * @returns a string representation of the error
0136      *
0137      * @snippet ex_data_source.c WT_EXTENSION_API map_windows_error
0138      */
0139     int (*map_windows_error)(WT_EXTENSION_API *wt_api, WT_SESSION *session, uint32_t windows_error);
0140 
0141     /*!
0142      * Allocate short-term use scratch memory.
0143      *
0144      * @param wt_api the extension handle
0145      * @param session the session handle (or NULL if none available)
0146      * @param bytes the number of bytes of memory needed
0147      * @returns A valid memory reference on success or NULL on error
0148      *
0149      * @snippet ex_data_source.c WT_EXTENSION_API scr_alloc
0150      */
0151     void *(*scr_alloc)(WT_EXTENSION_API *wt_api, WT_SESSION *session, size_t bytes);
0152 
0153     /*!
0154      * Free short-term use scratch memory.
0155      *
0156      * @param wt_api the extension handle
0157      * @param session the session handle (or NULL if none available)
0158      * @param ref a memory reference returned by WT_EXTENSION_API::scr_alloc
0159      *
0160      * @snippet ex_data_source.c WT_EXTENSION_API scr_free
0161      */
0162     void (*scr_free)(WT_EXTENSION_API *, WT_SESSION *session, void *ref);
0163 
0164     /*!
0165      * Configure the extension collator method.
0166      *
0167      * @param wt_api the extension handle
0168      * @param session the session handle (or NULL if none available)
0169      * @param uri the URI of the handle being configured
0170      * @param config the configuration information passed to an application
0171      * @param collatorp the selector collator, if any
0172      * @param ownp set if the collator terminate method should be called
0173      * when no longer needed
0174      * @errors
0175      *
0176      * @snippet ex_data_source.c WT_EXTENSION collator config
0177      */
0178     int (*collator_config)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *uri,
0179       WT_CONFIG_ARG *config, WT_COLLATOR **collatorp, int *ownp);
0180 
0181     /*!
0182      * The extension collator method.
0183      *
0184      * @param wt_api the extension handle
0185      * @param session the session handle (or NULL if none available)
0186      * @param collator the collator (or NULL if none available)
0187      * @param first first item
0188      * @param second second item
0189      * @param[out] cmp set less than 0 if \c first collates less than
0190      * \c second, set equal to 0 if \c first collates equally to \c second,
0191      * set greater than 0 if \c first collates greater than \c second
0192      * @errors
0193      *
0194      * @snippet ex_data_source.c WT_EXTENSION collate
0195      */
0196     int (*collate)(WT_EXTENSION_API *wt_api, WT_SESSION *session, WT_COLLATOR *collator,
0197       WT_ITEM *first, WT_ITEM *second, int *cmp);
0198 
0199     /*!
0200      * Return the value of a configuration key.
0201      *
0202      * @param wt_api the extension handle
0203      * @param session the session handle (or NULL if none available)
0204      * @param config the configuration information passed to an application
0205      * @param key configuration key string
0206      * @param value the returned value
0207      * @errors
0208      *
0209      * @snippet ex_data_source.c WT_EXTENSION config_get
0210      */
0211     int (*config_get)(WT_EXTENSION_API *wt_api, WT_SESSION *session, WT_CONFIG_ARG *config,
0212       const char *key, WT_CONFIG_ITEM *value);
0213 
0214     /*!
0215      * Return the value of a configuration key from a string.
0216      *
0217      * @param wt_api the extension handle
0218      * @param session the session handle (or NULL if none available)
0219      * @param config the configuration string
0220      * @param key configuration key string
0221      * @param value the returned value
0222      * @errors
0223      *
0224      * @snippet ex_data_source.c WT_EXTENSION config_get
0225      */
0226     int (*config_get_string)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *config,
0227       const char *key, WT_CONFIG_ITEM *value);
0228 
0229     /*!
0230      * @copydoc wiredtiger_config_parser_open
0231      */
0232     int (*config_parser_open)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *config,
0233       size_t len, WT_CONFIG_PARSER **config_parserp);
0234 
0235     /*!
0236      * @copydoc wiredtiger_config_parser_open
0237      */
0238     int (*config_parser_open_arg)(WT_EXTENSION_API *wt_api, WT_SESSION *session,
0239       WT_CONFIG_ARG *config, WT_CONFIG_PARSER **config_parserp);
0240 
0241     /*!
0242      * Insert a row into the metadata if it does not already exist.
0243      *
0244      * @param wt_api the extension handle
0245      * @param session the session handle (or NULL if none available)
0246      * @param key row key
0247      * @param value row value
0248      * @errors
0249      *
0250      * @snippet ex_data_source.c WT_EXTENSION metadata insert
0251      */
0252     int (*metadata_insert)(
0253       WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *key, const char *value);
0254 
0255     /*!
0256      * Remove a row from the metadata.
0257      *
0258      * @param wt_api the extension handle
0259      * @param session the session handle (or NULL if none available)
0260      * @param key row key
0261      * @errors
0262      *
0263      * @snippet ex_data_source.c WT_EXTENSION metadata remove
0264      */
0265     int (*metadata_remove)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *key);
0266 
0267     /*!
0268      * Return a row from the metadata.
0269      *
0270      * @param wt_api the extension handle
0271      * @param session the session handle (or NULL if none available)
0272      * @param key row key
0273      * @param [out] valuep the row value
0274      * @errors
0275      *
0276      * @snippet ex_data_source.c WT_EXTENSION metadata search
0277      */
0278     int (*metadata_search)(
0279       WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *key, char **valuep);
0280 
0281     /*!
0282      * Update a row in the metadata by either inserting a new record or
0283      * updating an existing record.
0284      *
0285      * @param wt_api the extension handle
0286      * @param session the session handle (or NULL if none available)
0287      * @param key row key
0288      * @param value row value
0289      * @errors
0290      *
0291      * @snippet ex_data_source.c WT_EXTENSION metadata update
0292      */
0293     int (*metadata_update)(
0294       WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *key, const char *value);
0295 
0296     /*!
0297      * Pack a structure into a buffer. Deprecated in favor of stream
0298      * based pack and unpack API. See WT_EXTENSION_API::pack_start for
0299      * details.
0300      *
0301      * @param wt_api the extension handle
0302      * @param session the session handle
0303      * @param buffer a pointer to a packed byte array
0304      * @param size the number of valid bytes in the buffer
0305      * @param format the data format, see @ref packing
0306      * @errors
0307      */
0308     int (*struct_pack)(WT_EXTENSION_API *wt_api, WT_SESSION *session, void *buffer, size_t size,
0309       const char *format, ...);
0310 
0311     /*!
0312      * Calculate the size required to pack a structure. Deprecated in
0313      * favor of stream based pack and unpack API.
0314      *
0315      * @param wt_api the extension handle
0316      * @param session the session handle
0317      * @param sizep a location where the number of bytes needed for the
0318      * matching call to WT_EXTENSION_API::struct_pack is returned
0319      * @param format the data format, see @ref packing
0320      * @errors
0321      */
0322     int (*struct_size)(
0323       WT_EXTENSION_API *wt_api, WT_SESSION *session, size_t *sizep, const char *format, ...);
0324 
0325     /*!
0326      * Unpack a structure from a buffer. Deprecated in favor of stream
0327      * based pack and unpack API. See WT_EXTENSION_API::unpack_start for
0328      * details.
0329      *
0330      * @param wt_api the extension handle
0331      * @param session the session handle
0332      * @param buffer a pointer to a packed byte array
0333      * @param size the number of valid bytes in the buffer
0334      * @param format the data format, see @ref packing
0335      * @errors
0336      */
0337     int (*struct_unpack)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const void *buffer,
0338       size_t size, const char *format, ...);
0339 
0340     /*
0341      * Streaming pack/unpack API.
0342      */
0343     /*!
0344      * Start a packing operation into a buffer.
0345      * See ::wiredtiger_pack_start for details.
0346      *
0347      * @param session the session handle
0348      * @param format the data format, see @ref packing
0349      * @param buffer a pointer to memory to hold the packed data
0350      * @param size the size of the buffer
0351      * @param[out] psp the new packing stream handle
0352      * @errors
0353      */
0354     int (*pack_start)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *format,
0355       void *buffer, size_t size, WT_PACK_STREAM **psp);
0356 
0357     /*!
0358      * Start an unpacking operation from a buffer.
0359      * See ::wiredtiger_unpack_start for details.
0360      *
0361      * @param session the session handle
0362      * @param format the data format, see @ref packing
0363      * @param buffer a pointer to memory holding the packed data
0364      * @param size the size of the buffer
0365      * @param[out] psp the new packing stream handle
0366      * @errors
0367      */
0368     int (*unpack_start)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *format,
0369       const void *buffer, size_t size, WT_PACK_STREAM **psp);
0370 
0371     /*!
0372      * Close a packing stream.
0373      *
0374      * @param ps the packing stream handle
0375      * @param[out] usedp the number of bytes in the buffer used by the
0376      * stream
0377      * @errors
0378      */
0379     int (*pack_close)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, size_t *usedp);
0380 
0381     /*!
0382      * Pack an item into a packing stream.
0383      *
0384      * @param ps the packing stream handle
0385      * @param item an item to pack
0386      * @errors
0387      */
0388     int (*pack_item)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, WT_ITEM *item);
0389 
0390     /*!
0391      * Pack a signed integer into a packing stream.
0392      *
0393      * @param ps the packing stream handle
0394      * @param i a signed integer to pack
0395      * @errors
0396      */
0397     int (*pack_int)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, int64_t i);
0398 
0399     /*!
0400      * Pack a string into a packing stream.
0401      *
0402      * @param ps the packing stream handle
0403      * @param s a string to pack
0404      * @errors
0405      */
0406     int (*pack_str)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, const char *s);
0407 
0408     /*!
0409      * Pack an unsigned integer into a packing stream.
0410      *
0411      * @param ps the packing stream handle
0412      * @param u an unsigned integer to pack
0413      * @errors
0414      */
0415     int (*pack_uint)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, uint64_t u);
0416 
0417     /*!
0418      * Unpack an item from a packing stream.
0419      *
0420      * @param ps the packing stream handle
0421      * @param item an item to unpack
0422      * @errors
0423      */
0424     int (*unpack_item)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, WT_ITEM *item);
0425 
0426     /*!
0427      * Unpack a signed integer from a packing stream.
0428      *
0429      * @param ps the packing stream handle
0430      * @param[out] ip the unpacked signed integer
0431      * @errors
0432      */
0433     int (*unpack_int)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, int64_t *ip);
0434 
0435     /*!
0436      * Unpack a string from a packing stream.
0437      *
0438      * @param ps the packing stream handle
0439      * @param[out] sp the unpacked string
0440      * @errors
0441      */
0442     int (*unpack_str)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, const char **sp);
0443 
0444     /*!
0445      * Unpack an unsigned integer from a packing stream.
0446      *
0447      * @param ps the packing stream handle
0448      * @param[out] up the unpacked unsigned integer
0449      * @errors
0450      */
0451     int (*unpack_uint)(WT_EXTENSION_API *wt_api, WT_PACK_STREAM *ps, uint64_t *up);
0452 
0453     /*!
0454      * Return the current transaction ID.
0455      *
0456      * @param wt_api the extension handle
0457      * @param session the session handle
0458      * @returns the current transaction ID.
0459      *
0460      * @snippet ex_data_source.c WT_EXTENSION transaction ID
0461      */
0462     uint64_t (*transaction_id)(WT_EXTENSION_API *wt_api, WT_SESSION *session);
0463 
0464     /*!
0465      * Return the current transaction's isolation level; returns one of
0466      * ::WT_TXN_ISO_READ_COMMITTED, ::WT_TXN_ISO_READ_UNCOMMITTED, or
0467      * ::WT_TXN_ISO_SNAPSHOT.
0468      *
0469      * @param wt_api the extension handle
0470      * @param session the session handle
0471      * @returns the current transaction's isolation level.
0472      *
0473      * @snippet ex_data_source.c WT_EXTENSION transaction isolation level
0474      */
0475     int (*transaction_isolation_level)(WT_EXTENSION_API *wt_api, WT_SESSION *session);
0476 
0477     /*!
0478      * Request notification of transaction resolution by specifying a
0479      * function to be called when the session's current transaction is
0480      * either committed or rolled back.  If the transaction is being
0481      * committed, but the notification function returns an error, the
0482      * transaction will be rolled back.
0483      *
0484      * @param wt_api the extension handle
0485      * @param session the session handle
0486      * @param notify a handler for commit or rollback events
0487      * @errors
0488      *
0489      * @snippet ex_data_source.c WT_EXTENSION transaction notify
0490      */
0491     int (*transaction_notify)(WT_EXTENSION_API *wt_api, WT_SESSION *session, WT_TXN_NOTIFY *notify);
0492 
0493     /*!
0494      * Return the oldest transaction ID not yet visible to a running
0495      * transaction.
0496      *
0497      * @param wt_api the extension handle
0498      * @param session the session handle
0499      * @returns the oldest transaction ID not yet visible to a running
0500      * transaction.
0501      *
0502      * @snippet ex_data_source.c WT_EXTENSION transaction oldest
0503      */
0504     uint64_t (*transaction_oldest)(WT_EXTENSION_API *wt_api);
0505 
0506     /*!
0507      * Return if the current transaction can see the given transaction ID.
0508      *
0509      * @param wt_api the extension handle
0510      * @param session the session handle
0511      * @param transaction_id the transaction ID
0512      * @returns true (non-zero) if the transaction ID is visible to the
0513      * current transaction.
0514      *
0515      * @snippet ex_data_source.c WT_EXTENSION transaction visible
0516      */
0517     int (*transaction_visible)(
0518       WT_EXTENSION_API *wt_api, WT_SESSION *session, uint64_t transaction_id);
0519 
0520     /*!
0521      * @copydoc wiredtiger_version
0522      */
0523     const char *(*version)(int *majorp, int *minorp, int *patchp);
0524 };
0525 
0526 /*!
0527  * @typedef WT_CONFIG_ARG
0528  *
0529  * A configuration object passed to some extension interfaces.  This is an
0530  * opaque type: configuration values can be queried using
0531  * WT_EXTENSION_API::config_get
0532  */
0533 
0534 /*! @} */
0535 #endif /* SWIG */
0536 
0537 #if defined(__cplusplus)
0538 }
0539 #endif
0540 #endif /* __WIREDTIGER_EXT_H_ */