Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implent snapshots support #313

Merged
merged 67 commits into from
Apr 9, 2023
Merged

Implent snapshots support #313

merged 67 commits into from
Apr 9, 2023

Conversation

danielealbano
Copy link
Owner

@danielealbano danielealbano commented Apr 9, 2023

This PR implements the necessary support to generate the RDB snapshots in the background.

A new fiber has been introduced which takes care of generating a snapshot, depending on the settings. A new set of parameters have been introduced, example below with explanation in line.

  snapshots:
    # The path where the snapshot file will be stored, if the rotation is enabled, the path will be used as prefix and
    # the timestamp of the start of the snapshot will be appended to the file name.
    path: /var/lib/cachegrand/dump.rdb
    # The interval between the snapshots, the allowed units are s, m, h, if not specified the default is seconds.
    interval: 5m
    # The number of keys that must be changed before a snapshot is taken, 0 means no limit
    min_keys_changed: 1000
    # The amount of data that must be changed before a snapshot is taken, the allowed units are b, k, m, g, if not
    min_data_changed: 100mb
    # Rotation settings, optional, if missing the snapshots rotation will be disabled
    rotation:
      # The max number of snapshots files to keep, minimum 2
      max_files: 10

The example is from cachegrand.yaml.skel

The new mechanism takes care of reporting every 3 seconds a status update.

Closes #293

Notes:

…criptors and implement it both for posix and io_uring
…s writable in the storage_db_snapshot unit, in config check only that the path is not longer than MAX_PATH
@danielealbano danielealbano added the enhancement New feature or request label Apr 9, 2023
@danielealbano danielealbano added this to the v0.2 milestone Apr 9, 2023
@danielealbano danielealbano added this to In Progress in cachegrand via automation Apr 9, 2023
@danielealbano danielealbano self-assigned this Apr 9, 2023
@danielealbano danielealbano linked an issue Apr 9, 2023 that may be closed by this pull request
@danielealbano danielealbano enabled auto-merge (squash) April 9, 2023 23:02
src/storage/db/storage_db_snapshot.h Fixed Show fixed Hide fixed
src/storage/db/storage_db_snapshot.c Fixed Show fixed Hide fixed
src/storage/db/storage_db_snapshot.c Fixed Show fixed Hide fixed
src/worker/storage/worker_storage_posix_op.c Fixed Show fixed Hide fixed
Comment on lines +455 to +485
// The LZF compression is disabled for now, it causes a segfault
// if (false && likely(!string_serialized || (entry_index->value.size > 32 && entry_index->value.size < 52 * 1024))) {
// module_redis_snapshot_serialize_primitive_result_t serialize_result;
// size_t allocated_buffer_size = LZF_MAX_COMPRESSED_SIZE(entry_index->value.size) * 1.2;
// uint8_t *allocated_buffer = ffma_mem_alloc(allocated_buffer_size);
//
// serialize_result = module_redis_snapshot_serialize_primitive_encode_small_string_lzf(
// string,
// entry_index->value.size,
// allocated_buffer,
// allocated_buffer_size,
// 0,
// &buffer_offset);
//
// // If the compression fails or the ration is too low ignore the error, cachegrand will try to
// // save the string as a regular string
// if (likely(serialize_result == MODULE_REDIS_SNAPSHOT_SERIALIZE_PRIMITIVE_RESULT_OK)) {
// if (unlikely(!storage_db_snapshot_rdb_write_buffer(
// db,
// allocated_buffer,
// allocated_buffer_size))) {
// ffma_mem_free(allocated_buffer);
// result = false;
// goto end;
// }
//
// string_serialized = true;
// }
//
// ffma_mem_free(allocated_buffer);
// }

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
hashtable_key_size_t key_size = 0;

// Tries to fetch the next entry within the block being processed
bucket_index++;

Check notice

Code scanning / CodeQL

For loop variable changed in body

Loop counters should not be modified in the body of the [loop](1).
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required by the implementation

@danielealbano danielealbano enabled auto-merge (squash) April 9, 2023 23:22
@danielealbano danielealbano merged commit c85fd82 into main Apr 9, 2023
cachegrand automation moved this from In Progress to Completed Apr 9, 2023
@danielealbano danielealbano deleted the feat-impl-snapshots-support branch April 9, 2023 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
cachegrand
  
Completed
Development

Successfully merging this pull request may close these issues.

Implement redis-compatible (RDB) snapshotting support
1 participant