Delete or Clear logfile created by libpmemlog

15 views
Skip to first unread message

Supriya Mishra SVNIT

unread,
Jun 16, 2023, 8:13:24 AM6/16/23
to pmem
Hi,

I have created a logfile using libpmemlog. I am able to append data to it using pmemlog_append() and print it using pmemlog_walk().

I want to delete it or clear its data but, I can't find any API for that.


If anyone can suggest how this can be done, that would be really helpful.


Thanks!

Andy Rudoff

unread,
Jun 16, 2023, 10:49:11 AM6/16/23
to pmem
Hi,

pmemlog_rewind() will reset the log to the empty state.  You mention "delete it or clear data" but the API is designed to use a dedicated range of pmem as a log for use cases that want to do a loop of append/walk/remind over time.  If you really want to delete the log just close it and unlink the file.  You could also append to one pmemlog, then when it is nearly full, create a new pmemlog and switch to appending to it while walking the first log followed by deleting it, ping-ponging between the two files over time.

-andy

Supriya Mishra SVNIT

unread,
Jun 17, 2023, 3:12:06 AM6/17/23
to pmem
Hi Andy,

Thank you for replying and the useful suggestions.

Following your suggestion, I tried pmemlog_rewind() and it enables to append the data in log from the beginning.
As you mentioned, my application requires to do loop of append/walk/remind. So, I have a related query:  How can I use the callback function "process_chunk()" to read the buf and setting the values of some fields required in my application. Here is the syntax of pmemlog_walk() API:

void pmemlog_walk(PMEMlogpool *plp, size_t chunksize, int(*process_chunk)(const void buf, size_t len, void *arg ), void *arg);


The process_chunk() function takes specified arguments namely, buf, len and arg. I don't understand what is the use of the argument arg and if this can be used in anyway setting the required fields.


I am also curious about how to check if the log is nearly full, close it and unlink for implementing the ping-pong solution.


Best Regards,

Supriya





Andy Rudoff

unread,
Jun 18, 2023, 11:19:19 AM6/18/23
to pmem

How can I use the callback function "process_chunk()" to read the buf and setting the values of some fields required in my application. Here is the syntax of pmemlog_walk() API:

void pmemlog_walk(PMEMlogpool *plp, size_t chunksize, int(*process_chunk)(const void buf, size_t len, void *arg ), void *arg);


The process_chunk() function takes specified arguments namely, buf, len and arg. I don't understand what is the use of the argument arg and if this can be used in anyway setting the required fields.



There's an example of a process_chunk function in the man page at: https://pmem.io/pmdk/libpmemlog/
The third argument is there in case you need to pass additional information through to your process_chunk callback.
If you don't have any additional information to pass, just ignore the third argument like the example does.
 

I am also curious about how to check if the log is nearly full, close it and unlink for implementing the ping-pong solution.


One way is to use pmemlog_tell() to return the current write point in the log.  Since there is some overhead used by pmemlog's bookkeeping, I don't think pmemlog_tell() can ever reach the full length that you passed to pmemlog_create(), but if you checked for it to return 80 or 90 percent of that size and ping-ponged at that point you should be fine.

An alternative implementation would be to use pmemlog_append() until it returns an error with errno set to ENOSPC, telling you the log is full, and then ping-pong to the other file at that point.

-andy
 

Supriya Mishra SVNIT

unread,
Jun 22, 2023, 4:18:04 AM6/22/23
to pmem
Thanks a lot!
Reply all
Reply to author
Forward
0 new messages