root/jlog_private.h

Revision c3c80874c84ec244ecc7a3c63473ad0eed55148c, 4.3 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 months ago)

Support a magic hdr in the reserved field other than 0

  • 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_SAFETY JLOG_ALMOST_SAFE
46 #define INDEX_EXT ".idx"
47 #define MAXLOGPATHLEN (MAXPATHLEN - (8+sizeof(INDEX_EXT)))
48
49 static const char __jlog_hexchars[] = "0123456789abcdef";
50
51 typedef enum {
52   JLOG_NEW = 0,
53   JLOG_INIT,
54   JLOG_READ,
55   JLOG_APPEND,
56   JLOG_INVALID
57 } jlog_mode;
58
59 struct _jlog_meta_info {
60   u_int32_t storage_log;
61   u_int32_t unit_limit;
62   u_int32_t safety;
63   u_int32_t hdr_magic;
64 };
65
66 struct _jlog_ctx {
67   struct _jlog_meta_info *meta;
68   int       meta_is_mapped;
69   struct _jlog_meta_info pre_init; /* only used before we're opened */
70   jlog_mode context_mode;
71   char      *path;
72   int       file_mode;
73   u_int32_t current_log;
74   jlog_file *data;
75   jlog_file *index;
76   jlog_file *checkpoint;
77   jlog_file *metastore;
78   void     *mmap_base;
79   size_t    mmap_len;
80   char     *subscriber_name;
81   int       last_error;
82   int       last_errno;
83   jlog_error_func error_func;
84   void *error_ctx;
85 };
86
87 /* macros */
88
89 #define STRLOGID(s, logid) do { \
90   int __i; \
91   for(__i=0;__i<8;__i++) \
92     (s)[__i] = __jlog_hexchars[((logid) >> (32 - ((__i+1)*4))) & 0xf]; \
93   (s)[__i] = '\0'; \
94 } while(0)
95
96 #define STRSETDATAFILE(ctx, file, log) do { \
97   int __len; \
98   __len = strlen((ctx)->path); \
99   memcpy((file), (ctx)->path, __len); \
100   (file)[__len] = IFS_CH; \
101   STRLOGID((file)+(__len+1), log); \
102 } while(0)
103
104 #define SYS_FAIL_EX(a, dowarn) do { \
105   if (ctx) { \
106     ctx->last_error = (a); \
107     ctx->last_errno = errno; \
108     if(ctx->error_func && dowarn) { \
109       ctx->error_func(ctx->error_ctx, \
110                       "JLOG-%d error: %d (%s) errno: %d (%s)\n", __LINE__, \
111                       ctx->last_error, jlog_ctx_err_string(ctx), \
112                       ctx->last_errno, strerror(ctx->last_errno)); \
113     } \
114   } \
115   goto finish; \
116 } while(0)
117
118 #define SYS_FAIL(a) SYS_FAIL_EX(a, 1)
119
120 /**
121  * repairs a damaged datafile
122  * @return 0 OK, >0 number of damaged segments removed, -1 repair failed
123  * @internal
124  */
125 JLOG_API(int) jlog_repair_datafile(jlog_ctx *ctx, u_int32_t log);
126 /**
127  * prints detailed info about the log segment to stderr
128  * @return 0 OK, 1 segment damaged, -1 other error
129  * @internal
130  */
131 JLOG_API(int) jlog_inspect_datafile(jlog_ctx *ctx, u_int32_t log, int verbose);
132 /**
133  * fetches the last marker in the index and the closedness thereof
134  * @return 0 OK, -1 error
135  * @internal
136  */
137 JLOG_API(int) jlog_idx_details(jlog_ctx *ctx, u_int32_t log,
138                                u_int32_t *marker, int *closed);
139
140
141 #ifdef _WIN32
142 #include "ec_win32.h"
143 #endif
144
145 #endif
Note: See TracBrowser for help on using the browser.