root/jlog_private.h

Revision b3e61c55620ec1ab5043a1c727194d8e7fd8655f, 5.1 kB (checked in by Riley Berton <riley.berton@circonus.com>, 3 months ago)

Enhance throughput by using a pre-commit buffer space along with a multi-process control setting

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2005-2008, Message Systems, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *    * Redistributions of source code must retain the above copyright
10  *      notice, this list of conditions and the following disclaimer.
11  *    * Redistributions in binary form must reproduce the above
12  *      copyright notice, this list of conditions and the following
13  *      disclaimer in the documentation and/or other materials provided
14  *      with the distribution.
15  *    * Neither the name Message Systems, Inc. nor the names
16  *      of its contributors may be used to endorse or promote products
17  *      derived from this software without specific prior written
18  *      permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _JLOG_PRIVATE_H
34 #define _JLOG_PRIVATE_H
35 /* vim:se ts=2 sw=2 et: */
36
37 #include "jlog_config.h"
38 #include "jlog.h"
39 #include "jlog_io.h"
40
41 #define DEFAULT_FILE_MODE 0640
42 #define DEFAULT_UNIT_LIMIT (4*1024*1024)
43                          /* 4 Megabytes */
44 #define DEFAULT_HDR_MAGIC 0x663A7318
45 #define DEFAULT_HDR_MAGIC_COMPRESSION 0x15106A00
46 #define DEFAULT_SAFETY JLOG_ALMOST_SAFE
47 #define INDEX_EXT ".idx"
48 #define MAXLOGPATHLEN (MAXPATHLEN - (8+sizeof(INDEX_EXT)))
49
50 static const char __jlog_hexchars[] = "0123456789abcdef";
51
52 typedef enum {
53   JLOG_NEW = 0,
54   JLOG_INIT,
55   JLOG_READ,
56   JLOG_APPEND,
57   JLOG_INVALID
58 } jlog_mode;
59
60 struct _jlog_meta_info {
61   u_int32_t storage_log;
62   u_int32_t unit_limit;
63   u_int32_t safety;
64   u_int32_t hdr_magic;
65 };
66
67 struct _jlog_ctx {
68   struct _jlog_meta_info *meta;
69   pthread_mutex_t write_lock;
70   int       meta_is_mapped;
71   int       pre_commit_is_mapped;
72   uint8_t   multi_process;
73   void      *pre_commit_buffer;
74   void      *pre_commit_pos;
75   void      *pre_commit_end;
76   size_t    pre_commit_buffer_len;
77   uint32_t  *pre_commit_pointer;
78   struct _jlog_meta_info pre_init; /* only used before we're opened */
79   jlog_mode context_mode;
80   char      *path;
81   int       file_mode;
82   u_int32_t current_log;
83   jlog_file *data;
84   jlog_file *index;
85   jlog_file *checkpoint;
86   jlog_file *metastore;
87   jlog_file *pre_commit;
88   void     *mmap_base;
89   size_t    mmap_len;
90   char     *subscriber_name;
91   int       last_error;
92   int       last_errno;
93   jlog_error_func error_func;
94   void *error_ctx;
95
96   /**
97    * Store the last read message in the case of use_compression == 1.
98    * There is an expectation from jlog user's that they are handed
99    * mmap'd memory directly and that they don't have to free it, so we
100    * have to maintain a block of memory where we can decompress messages
101    * and hand them back.  The contract being that everytime jlog_ctx_read_message
102    * is called, we overwrite this memory with the new message
103    */
104   size_t    mess_data_size;
105   char      *mess_data;
106 };
107
108 /* macros */
109
110 #define STRLOGID(s, logid) do { \
111   int __i; \
112   for(__i=0;__i<8;__i++) \
113     (s)[__i] = __jlog_hexchars[((logid) >> (32 - ((__i+1)*4))) & 0xf]; \
114   (s)[__i] = '\0'; \
115 } while(0)
116
117 #define STRSETDATAFILE(ctx, file, log) do { \
118   int __len; \
119   __len = strlen((ctx)->path); \
120   memcpy((file), (ctx)->path, __len); \
121   (file)[__len] = IFS_CH; \
122   STRLOGID((file)+(__len+1), log); \
123 } while(0)
124
125 #define SYS_FAIL_EX(a, dowarn) do { \
126   if (ctx) { \
127     ctx->last_error = (a); \
128     ctx->last_errno = errno; \
129     if(ctx->error_func && dowarn) { \
130       ctx->error_func(ctx->error_ctx, \
131                       "JLOG-%d error: %d (%s) errno: %d (%s)\n", __LINE__, \
132                       ctx->last_error, jlog_ctx_err_string(ctx), \
133                       ctx->last_errno, strerror(ctx->last_errno)); \
134     } \
135   } \
136   goto finish; \
137 } while(0)
138
139 #define SYS_FAIL(a) SYS_FAIL_EX(a, 1)
140
141 /**
142  * repairs a damaged datafile
143  * @return 0 OK, >0 number of damaged segments removed, -1 repair failed
144  * @internal
145  */
146 JLOG_API(int) jlog_repair_datafile(jlog_ctx *ctx, u_int32_t log);
147 /**
148  * prints detailed info about the log segment to stderr
149  * @return 0 OK, 1 segment damaged, -1 other error
150  * @internal
151  */
152 JLOG_API(int) jlog_inspect_datafile(jlog_ctx *ctx, u_int32_t log, int verbose);
153 /**
154  * fetches the last marker in the index and the closedness thereof
155  * @return 0 OK, -1 error
156  * @internal
157  */
158 JLOG_API(int) jlog_idx_details(jlog_ctx *ctx, u_int32_t log,
159                                u_int32_t *marker, int *closed);
160
161
162 #ifdef _WIN32
163 #include "ec_win32.h"
164 #endif
165
166 #endif
Note: See TracBrowser for help on using the browser.