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

feat(storage): store old value in memtable #15301

Merged
merged 8 commits into from
Apr 24, 2024
Merged

Conversation

wenym1
Copy link
Contributor

@wenym1 wenym1 commented Feb 27, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

After #15300 and #15417

In this PR, we will compact and upload the old values of state store when is_log_store is enabled.

In SharedBufferBatch, when is_log_store is enabled, an extra old_value of type Vec<Bytes> will be used to stored the old value. The new_value of shared buffer batch now stores a new enum SharedBufferValue. The difference to the previously used HummockValue is that SharedBufferValue has an extra enum case Update to indicate that the operation is an update. When the enum is Delete and Update the value in old_value will be the corresponding old value, and for Insert, it means there is no old value for the current key op, and the value will be an empty bytes. Therefore, the old_value has the same length as the new_value.

In SharedBufferBatchIterator, we add a new generic const bool IS_NEW_VALUE to indicate whether the iterator is iterating over new value or old value. If IS_NEW_VALUE is true, the logic will be the same as original. If IS_NEW_VALUE is false, the value method will take the value from the old_value, and in the next_call, we will further advance the iterator to skip the key with op as Insert, because Insert has no old value.

The old value will be compacted to separate SSTs and add to hummock version.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Copy link
Collaborator

@hzxa21 hzxa21 left a comment

Choose a reason for hiding this comment

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

Generally LGTM. But I think we need more documentation in the codes on this feature to ensure people have less contexts on the RFC can get the basic ideas.

kv_pairs.push((key, StorageValue::new_put(value)));
kv_pairs.push((key, SharedBufferValue::Insert(value)));
if let Some(old_values) = &mut old_values {
old_values.push(Bytes::new());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will we have an entry in the old value SST for KeyOp::Insert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. In SharedBufferBatchIterator, when IS_NEW_VALUE is false, at the end of the next call, we will have an extra advance_until_valid_old_value to skip the KeyOp::Insert

@wenym1 wenym1 changed the base branch from main to yiming/hummock-iter-log April 10, 2024 06:41
Base automatically changed from yiming/hummock-iter-log to main April 18, 2024 15:18
@wenym1 wenym1 marked this pull request as ready for review April 22, 2024 05:15
@wenym1 wenym1 force-pushed the yiming/old-value-memtable branch from ad0e146 to 43c84c3 Compare April 22, 2024 06:36
@wenym1 wenym1 requested review from hzxa21, Li0k, MrCroxx and xxhZs April 22, 2024 07:53
Copy link
Collaborator

@hzxa21 hzxa21 left a comment

Choose a reason for hiding this comment

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

Left some minor comments. Rest LGTM!

src/storage/hummock_sdk/src/change_log.rs Show resolved Hide resolved
}
}
}
table_change_log
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is guaranteed that entries in table_change_log should have both non-empty new_value and non-empty old_value. Can we add an assertion to check that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just thought of a corner case, will we generate a old_value sst if there are only INSERTs in new_value sst? Correct me if I am wrong, I think we will generate a old_value sst with no entries in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By design, if there is no data, we will still have an empty EpochNewChangeLog to store the epochs information so that when we replay we won't miss a barrier.

I just checked the code. Currently the sst builder is initialized lazily. So if the payload is append only, the old value imm iterator won't have any output, and then no sst will be built.

HummockValue::Put(val) => val.len(),
HummockValue::Delete => 0,
SharedBufferValue::Insert(val) | SharedBufferValue::Update(val) => {
val.len()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add size_of_val here as well?

@wenym1 wenym1 added this pull request to the merge queue Apr 24, 2024
Merged via the queue into main with commit 38f98f5 Apr 24, 2024
30 of 31 checks passed
@wenym1 wenym1 deleted the yiming/old-value-memtable branch April 24, 2024 07:48
Li0k added a commit that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants