pmemlog – pmem-resident log file

class nvm.pmemlog.LogPool(log_pool)

This class represents the Log Pool opened or created using create() or open().


This method appends from buffer to the current write offset in the log memory pool plp. Calling this function is analogous to appending to a file. The append is atomic and cannot be torn by a program failure or system crash.

On success, zero is returned. On error, -1 is returned and errno is set.


This method closes the memory pool. The log memory pool itself lives on in the file that contains it and may be re-opened at a later time using open().


This method returns the amount of usable space in the log pool. This method may be used to determine how much usable space is available after libpmemlog has added its metadata to the memory pool.


You can also use len() to get the usable space.

Returns:amount of usable space in the log pool.

This method resets the current write point for the log to zero. After this call, the next append adds to the beginning of the log.


This method returns the current write point for the log, expressed as a byte offset into the usable log space in the memory pool. This offset starts off as zero on a newly-created log, and is incremented by each successful append operation. This function can be used to determine how much data is currently in the log.

Returns:the current write point for the log, expressed as a byte offset.
walk(func, chunk_size=0)

This function walks through the log pool, from beginning to end, calling the callback function for each chunksize block of data found. The chunksize argument is useful for logs with fixed-length records and may be specified as 0 to cause a single call to the callback with the entire log contents.

  • chunk_size – chunk size or 0 for total length (default to 0).
  • func – the callback function, should return 1 if it should continue walking through the log, or 0 to terminate the walk.

This method performs a consistency check of the file indicated and returns True if the memory pool is found to be consistent. Any inconsistencies found will cause this function to return False, in which case the use of the file with libpmemlog will result in undefined behavior.

Returns:True if memory pool is consistent, False otherwise.
nvm.pmemlog.check_version(major_required, minor_required)

Checks the libpmemlog version according to the specified major and minor versions required.

  • major_required – Major version required.
  • minor_required – Minor version required.

returns True if the nvm has the required version, or raises a RuntimeError exception in case of failure.

nvm.pmemlog.create(filename, pool_size=<Mock id='140327076957008'>, mode=438)

The create() function creates a log memory pool with the given total pool_size. Since the transactional nature of a log memory pool requires some space overhead in the memory pool, the resulting available log size is less than poolsize, and is made available to the caller via the nbyte() function.


If the error prevents any of the pool set files from being created, this function will raise an exception.

  • filename – specifies the name of the memory pool file to be created.
  • pool_size – the size of the pool (defaults to PMEMLOG_MIN_POOL).
  • mode – specifies the permissions to use when creating the file.

the new log memory pool created.

Return type:


This function opens an existing log memory pool, returning a memory pool.


If an error prevents the pool from being opened, this function will rise an exception.

Parameters:filename – Filename must be an existing file containing a log memory pool as created by the create() method. The application must have permission to open the file and memory map it with read/write permissions.
Returns:the log memory pool.
Return type:LogPool