1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
.\" Automatically generated by Pandoc 2.1.3
.\"
.TH "LIBPMEMLOG" "7" "2018-10-17" "PMDK - pmemlog API version 1.1" "PMDK Programmer's Manual"
.hy
.\" Copyright 2014-2018, Intel Corporation
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" * Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" * Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\"
.\" * Neither the name of the copyright holder nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
.\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.SH NAME
.PP
\f[B]libpmemlog\f[] \- persistent memory resident log file
.SH SYNOPSIS
.IP
.nf
\f[C]
#include\ <libpmemlog.h>
cc\ ...\ \-lpmemlog\ \-lpmem
\f[]
.fi
.SS Library API versioning:
.IP
.nf
\f[C]
const\ char\ *pmemlog_check_version(
\ \ \ \ unsigned\ major_required,
\ \ \ \ unsigned\ minor_required);
\f[]
.fi
.SS Managing library behavior:
.IP
.nf
\f[C]
void\ pmemlog_set_funcs(
\ \ \ \ void\ *(*malloc_func)(size_t\ size),
\ \ \ \ void\ (*free_func)(void\ *ptr),
\ \ \ \ void\ *(*realloc_func)(void\ *ptr,\ size_t\ size),
\ \ \ \ char\ *(*strdup_func)(const\ char\ *s));
\f[]
.fi
.SS Error handling:
.IP
.nf
\f[C]
int\ pmemlog_check(const\ char\ *path);
\f[]
.fi
.SS Other library functions:
.PP
A description of other \f[B]libpmemlog\f[] functions can be found on the
following manual pages:
.PP
\f[B]pmemlog_append\f[](3), \f[B]pmemlog_create\f[](3),
\f[B]pmemlog_ctl_exec\f[](3), \f[B]pmemlog_ctl_get\f[](3),
\f[B]pmemlog_ctl_set\f[](3), \f[B]pmemlog_nbyte\f[](3),
\f[B]pmemlog_tell\f[](3)
.SH DESCRIPTION
.PP
\f[B]libpmemlog\f[] provides a log file in \f[I]persistent memory\f[]
(pmem) such that additions to the log are appended atomically.
This library is intended for applications using direct access storage
(DAX), which is storage that supports load/store access without paging
blocks from a block storage device.
Some types of \f[I]non\-volatile memory DIMMs\f[] (NVDIMMs) provide this
type of byte addressable access to storage.
A \f[I]persistent memory aware file system\f[] is typically used to
expose the direct access to applications.
Memory mapping a file from this type of file system results in the
load/store, non\-paged access to pmem.
\f[B]libpmemlog\f[] builds on thistype of memory mapped file.
.PP
This library is for applications that need a persistent log file updated
atomically (the updates cannot be \f[I]torn\f[] by program interruption
such as power failures).
This library builds on the low\-level pmem support provided by
\f[B]libpmem\f[](7), handling the transactional update of the log,
flushing to persistence, and recovery for the application.
.PP
\f[B]libpmemlog\f[] is one of a collection of persistent memory
libraries available.
The others are:
.IP \[bu] 2
\f[B]libpmemobj\f[](7), a general use persistent memory API, providing
memory allocation and transactional operations on variable\-sized
objects.
.IP \[bu] 2
\f[B]libpmemblk\f[](7), providing pmem\-resident arrays of fixed\-sized
blocks with atomic updates.
.IP \[bu] 2
\f[B]libpmem\f[](7), low\-level persistent memory support.
.PP
Under normal usage, \f[B]libpmemlog\f[] will never print messages or
intentionally cause the process to exit.
The only exception to this is the debugging information, when enabled,
as described under \f[B]DEBUGGING AND ERROR HANDLING\f[] below.
.PP
To use the pmem\-resident log file provided by \f[B]libpmemlog\f[], a
\f[I]memory pool\f[] is first created.
This is done with the \f[B]pmemlog_create\f[](3) function.
The other functions mentioned above in SYNOPSIS section then operate on
the resulting log memory pool.
.PP
Once created, the memory pool is represented by an opaque handle, of
type \f[I]PMEMlogpool*\f[], which is passed to most of the other
functions from \f[B]libpmemlog\f[].
Internally, \f[B]libpmemlog\f[] will use either \f[B]pmem_persist\f[](3)
or \f[B]msync\f[](2) when it needs to flush changes, depending on
whether the memory pool appears to be persistent memory or a regular
file (see the \f[B]pmem_is_pmem\f[](3) function in \f[B]libpmem\f[](7)
for more information).
There is no need for applications to flush changes directly when using
the log memory API provided by \f[B]libpmemlog\f[].
.SH CAVEATS
.PP
\f[B]libpmemlog\f[] relies on the library destructor being called from
the main thread.
For this reason, all functions that might trigger destruction (e.g.
\f[B]dlclose\f[](3)) should be called in the main thread.
Otherwise some of the resources associated with that thread might not be
cleaned up properly.
.SH LIBRARY API VERSIONING
.PP
This section describes how the library API is versioned, allowing
applications to work with an evolving API.
.PP
The \f[B]pmemlog_check_version\f[]() function is used to determine
whether the installed \f[B]libpmemlog\f[] supports the version of the
library API required by an application.
The easiest way to do this is for the application to supply the
compile\-time version information provided by defines in
\f[B]<libpmemlog.h>\f[], like this:
.IP
.nf
\f[C]
reason\ =\ pmemlog_check_version(PMEMLOG_MAJOR_VERSION,
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ PMEMLOG_MINOR_VERSION);
if\ (reason\ !=\ NULL)\ {
\ \ \ \ /*\ version\ check\ failed,\ reason\ string\ tells\ you\ why\ */
}
\f[]
.fi
.PP
Any mismatch in the major version number is considered a failure, but a
library with a newer minor version number will pass this check since
increasing minor versions imply backwards compatibility.
.PP
An application can also check specifically for the existence of an
interface by checking for the version where that interface was
introduced.
These versions are documented in this man page as follows: unless
otherwise specified, all interfaces described here are available in
version 1.0 of the library.
Interfaces added after version 1.0 will contain the text \f[I]introduced
in version x.y\f[] in the section of this manual describing the feature.
.PP
On success, \f[B]pmemlog_check_version\f[]() returns NULL.
Otherwise, the return value is a static string describing the reason the
version check failed.
The string returned by \f[B]pmemlog_check_version\f[]() must not be
modified or freed.
.SH MANAGING LIBRARY BEHAVIOR
.PP
The \f[B]pmemlog_set_funcs\f[]() function allows an application to
override memory allocation calls used internally by \f[B]libpmemlog\f[].
Passing in NULL for any of the handlers will cause the
\f[B]libpmemlog\f[] default function to be used.
The library does not make heavy use of the system malloc functions, but
it does allocate approximately 4\-8 kilobytes for each memory pool in
use.
.SH DEBUGGING AND ERROR HANDLING
.PP
The \f[B]pmemlog_errormsg\f[]() function returns a pointer to a static
buffer containing the last error message logged for the current thread.
If \f[I]errno\f[] was set, the error message may include a description
of the corresponding error code as returned by \f[B]strerror\f[](3).
The error message buffer is thread\-local; errors encountered in one
thread do not affect its value in other threads.
The buffer is never cleared by any library function; its content is
significant only when the return value of the immediately preceding call
to a \f[B]libpmemlog\f[] function indicated an error, or if
\f[I]errno\f[] was set.
The application must not modify or free the error message string, but it
may be modified by subsequent calls to other library functions.
.PP
Two versions of \f[B]libpmemlog\f[] are typically available on a
development system.
The normal version, accessed when a program is linked using the
\f[B]\-lpmemlog\f[] option, is optimized for performance.
That version skips checks that impact performance and never logs any
trace information or performs any run\-time assertions.
.PP
A second version of \f[B]libpmemlog\f[], accessed when a program uses
the libraries under \f[B]/usr/lib/pmdk_debug\f[], contains run\-time
assertions and trace points.
The typical way to access the debug version is to set the environment
variable \f[B]LD_LIBRARY_PATH\f[] to \f[B]/usr/lib/pmdk_debug\f[] or
\f[B]/usr/lib64/pmdk_debug\f[], as appropriate.
Debugging output is controlled using the following environment
variables.
These variables have no effect on the non\-debug version of the library.
.IP \[bu] 2
\f[B]PMEMLOG_LOG_LEVEL\f[]
.PP
The value of \f[B]PMEMLOG_LOG_LEVEL\f[] enables trace points in the
debug version of the library, as follows:
.IP \[bu] 2
\f[B]0\f[] \- This is the default level when \f[B]PMEMLOG_LOG_LEVEL\f[]
is not set.
No log messages are emitted at this level.
.IP \[bu] 2
\f[B]1\f[] \- Additional details on any errors detected are logged, in
addition to returning the \f[I]errno\f[]\-based errors as usual.
The same information may be retrieved using \f[B]pmemlog_errormsg\f[]().
.IP \[bu] 2
\f[B]2\f[] \- A trace of basic operations is logged.
.IP \[bu] 2
\f[B]3\f[] \- Enables a very verbose amount of function call tracing in
the library.
.IP \[bu] 2
\f[B]4\f[] \- Enables voluminous and fairly obscure tracing information
that is likely only useful to the \f[B]libpmemlog\f[] developers.
.PP
Unless \f[B]PMEMLOG_LOG_FILE\f[] is set, debugging output is written to
\f[I]stderr\f[].
.IP \[bu] 2
\f[B]PMEMLOG_LOG_FILE\f[]
.PP
Specifies the name of a file name where all logging information should
be written.
If the last character in the name is \[lq]\-\[rq], the \f[I]PID\f[] of
the current process will be appended to the file name when the log file
is created.
If \f[B]PMEMLOG_LOG_FILE\f[] is not set, logging output is written to
\f[I]stderr\f[].
.PP
See also \f[B]libpmem\f[](7) for information about other environment
variables affecting \f[B]libpmemlog\f[] behavior.
.SH EXAMPLE
.PP
The following example illustrates how the \f[B]libpmemlog\f[] API is
used.
.IP
.nf
\f[C]
#include\ <stdio.h>
#include\ <fcntl.h>
#include\ <errno.h>
#include\ <stdlib.h>
#include\ <unistd.h>
#include\ <string.h>
#include\ <libpmemlog.h>
/*\ size\ of\ the\ pmemlog\ pool\ \-\-\ 1\ GB\ */
#define\ POOL_SIZE\ ((size_t)(1\ <<\ 30))
/*
\ *\ printit\ \-\-\ log\ processing\ callback\ for\ use\ with\ pmemlog_walk()
\ */
int
printit(const\ void\ *buf,\ size_t\ len,\ void\ *arg)
{
\ \ \ \ fwrite(buf,\ len,\ 1,\ stdout);
\ \ \ \ return\ 0;
}
int
main(int\ argc,\ char\ *argv[])
{
\ \ \ \ const\ char\ path[]\ =\ "/pmem\-fs/myfile";
\ \ \ \ PMEMlogpool\ *plp;
\ \ \ \ size_t\ nbyte;
\ \ \ \ char\ *str;
\ \ \ \ /*\ create\ the\ pmemlog\ pool\ or\ open\ it\ if\ it\ already\ exists\ */
\ \ \ \ plp\ =\ pmemlog_create(path,\ POOL_SIZE,\ 0666);
\ \ \ \ if\ (plp\ ==\ NULL)
\ \ \ \ \ \ \ \ plp\ =\ pmemlog_open(path);
\ \ \ \ if\ (plp\ ==\ NULL)\ {
\ \ \ \ \ \ \ \ perror(path);
\ \ \ \ \ \ \ \ exit(1);
\ \ \ \ }
\ \ \ \ /*\ how\ many\ bytes\ does\ the\ log\ hold?\ */
\ \ \ \ nbyte\ =\ pmemlog_nbyte(plp);
\ \ \ \ printf("log\ holds\ %zu\ bytes",\ nbyte);
\ \ \ \ /*\ append\ to\ the\ log...\ */
\ \ \ \ str\ =\ "This\ is\ the\ first\ string\ appended";
\ \ \ \ if\ (pmemlog_append(plp,\ str,\ strlen(str))\ <\ 0)\ {
\ \ \ \ \ \ \ \ perror("pmemlog_append");
\ \ \ \ \ \ \ \ exit(1);
\ \ \ \ }
\ \ \ \ str\ =\ "This\ is\ the\ second\ string\ appended";
\ \ \ \ if\ (pmemlog_append(plp,\ str,\ strlen(str))\ <\ 0)\ {
\ \ \ \ \ \ \ \ perror("pmemlog_append");
\ \ \ \ \ \ \ \ exit(1);
\ \ \ \ }
\ \ \ \ /*\ print\ the\ log\ contents\ */
\ \ \ \ printf("log\ contains:");
\ \ \ \ pmemlog_walk(plp,\ 0,\ printit,\ NULL);
\ \ \ \ pmemlog_close(plp);
}
\f[]
.fi
.PP
See <http://pmem.io/pmdk/libpmemlog> for more examples using the
\f[B]libpmemlog\f[] API.
.SH BUGS
.PP
Unlike \f[B]libpmemobj\f[](7), data replication is not supported in
\f[B]libpmemlog\f[].
Thus, specifying replica sections in pool set files is not allowed.
.SH ACKNOWLEDGEMENTS
.PP
\f[B]libpmemlog\f[] builds on the persistent memory programming model
recommended by the SNIA NVM Programming Technical Work Group:
<http://snia.org/nvmp>
.SH SEE ALSO
.PP
\f[B]msync\f[](2), \f[B]pmemlog_append\f[](3),
\f[B]pmemlog_create\f[](3), \f[B]pmemlog_ctl_exec\f[](3),
\f[B]pmemlog_ctl_get\f[](3), \f[B]pmemlog_ctl_set\f[](3),
\f[B]pmemlog_nbyte\f[](3), \f[B]pmemlog_tell\f[](3),
\f[B]strerror\f[](3), \f[B]libpmem\f[](7), \f[B]libpmemblk\f[](7),
\f[B]libpmemobj\f[](7) and \f[B]<http://pmem.io>\f[]
|