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

Adding basic version of DUMP and RESTORE commands #899

Merged

Conversation

s3w3nofficial
Copy link
Contributor

Currently only work's on string type and does not support compression, but it's still a solid starting point.

Implemented

  • redis length encoding
  • redis compatible crc64 implementation
  • DUMP command that works on strings without compression
  • RESTORE command that works on strings without compression and additional modifiers

Not Implemented

  • support for other types than strings
  • support for lzf compression
  • optional modifiers for RESTORE

Also about the copyright for the crc64, i only ported the pycrc generated version, but still i'm not sure if and which copyright should i add.

@s3w3nofficial
Copy link
Contributor Author

@microsoft-github-policy-service agree

@s3w3nofficial s3w3nofficial force-pushed the s3w3nofficial/add-dump-and-restore-command branch from f9c9838 to 2954d6e Compare January 3, 2025 01:24
@badrishc
Copy link
Contributor

badrishc commented Jan 6, 2025

Also about the copyright for the crc64, i only ported the pycrc generated version, but still i'm not sure if and which copyright should i add.

since you only ported the pycrc generated version, it seems we should be okay as it is ...

@TalZaccai TalZaccai requested a review from vazois January 7, 2025 19:28
@TalZaccai TalZaccai linked an issue Jan 14, 2025 that may be closed by this pull request
@vazois
Copy link
Contributor

vazois commented Jan 14, 2025

@s3w3nofficial, any updates on the open comments?

@s3w3nofficial
Copy link
Contributor Author

@s3w3nofficial, any updates on the open comments?

Only open comment left is from @badrishc about the renaming which i already implemented, i guess i can close that one ?

Copy link
Contributor

@vazois vazois left a comment

Choose a reason for hiding this comment

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

LGTM!

@s3w3nofficial
Copy link
Contributor Author

Every test is passing except the RestoreACLsAsync. It throws this exception: "NOAUTH Authentication required.".

I can't figure out why. Can you guys please take a look at it ?

@vazois vazois self-requested a review January 16, 2025 17:50
@badrishc
Copy link
Contributor

Every test is passing except the RestoreACLsAsync. It throws this exception: "NOAUTH Authentication required.".

I can't figure out why. Can you guys please take a look at it ?

@kevin-montrose, can you help how to fix the ACL unit test here? The error is:

image

@kevin-montrose
Copy link
Contributor

Every test is passing except the RestoreACLsAsync. It throws this exception: "NOAUTH Authentication required.".
I can't figure out why. Can you guys please take a look at it ?

@kevin-montrose, can you help how to fix the ACL unit test here? The error is:

image

@badrishc @s3w3nofficial I suspect it's that try/catch not leaving the client in a nice state when an exception is encountered. The pattern elsewhere for ACLs with commands that aren't repeatable is to use a counter to differentiate each invocation.

[Test]
public async Task RestoreACLsAsync()
{
    var count = 0;

    await CheckCommandsAsync(
        "RESTORE",
        [DoRestoreAsync]
    );

    async Task DoRestoreAsync(GarnetClient client)
    {
        var payload = new byte[]
        {
            0x00, // value type 
            0x03, // length of payload
            0x76, 0x61, 0x6C,       // 'v', 'a', 'l'
            0x0B, 0x00, // RDB version
            0xDB, 0x82, 0x3C, 0x30, 0x38, 0x78, 0x5A, 0x99 // Crc64
        };

        count++;

        var val = await client.ExecuteForStringResultAsync(
            "$7\r\nRESTORE\r\n"u8.ToArray(),
            [
                Encoding.UTF8.GetBytes($"foo-{count}"), 
                "0"u8.ToArray(), 
                payload
            ]);

        ClassicAssert.AreEqual("OK", val);
    }
}

Works, and all ACL tests pass.

Copy link
Contributor

@kevin-montrose kevin-montrose left a comment

Choose a reason for hiding this comment

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

Lots of little notes for improvements, and a couple questions around correctness.

@s3w3nofficial
Copy link
Contributor Author

Hey @kevin-montrose

Thanks for the help with test and for the comments. I will try to resolve these over the weekend.

Regarding the parsing, i'm working on a parser that support's the whole rdb format and i hope i will be able to implement that one in the future. For now i will look into optimizing the RespLengthEncodingUtils since the parser won't be ready any time soon.

@badrishc
Copy link
Contributor

badrishc commented Jan 22, 2025

This PR looks ok, although a few spots for improvement remain:

  • There should ideally be no need to copy over the entire value retrieved from the back-end to a temporary buffer. Instead, we would directly write the RDB-formatted output (with CRC) to the output buffer in the back-end logic, similar to the CopyRespTo calls.
  • There needs to be a BDN in RawStringOperations to measure and improve the performance of DUMP and RESTORE.

However, these require deeper surgery than necessary, so we can go ahead and approve/merge this PR as is, and revisit later as per needs. Thank you.

@badrishc badrishc merged commit 7483efc into microsoft:main Jan 22, 2025
15 checks passed
@s3w3nofficial s3w3nofficial deleted the s3w3nofficial/add-dump-and-restore-command branch January 23, 2025 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DUMP Command Not Supported in Garnet
7 participants