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

Using the remote bytes the instead of the serialized bytes during the transaction #2198

Closed
WenyXu opened this issue Aug 17, 2023 · 0 comments · Fixed by #2538
Closed

Using the remote bytes the instead of the serialized bytes during the transaction #2198

WenyXu opened this issue Aug 17, 2023 · 0 comments · Fixed by #2538
Assignees
Labels
C-enhancement Category Enhancements

Comments

@WenyXu
Copy link
Member

WenyXu commented Aug 17, 2023

What type of enhancement is this?

Refactor, Tech debt reduction

What does the enhancement do?

  /// Builds a update table info transaction, it expected the remote value equals the `current_current_table_info_value`.
    /// It retrieves the latest value if the comparing failed.
    pub(crate) fn build_update_txn(
        &self,
        table_id: TableId,
        current_table_info_value: &TableInfoValue,
        new_table_info_value: &TableInfoValue,
    ) -> Result<(
        Txn,
        impl FnOnce(&Vec<TxnOpResponse>) -> Result<Option<TableInfoValue>>,
    )> {
        let key = TableInfoKey::new(table_id);
        let raw_key = key.as_raw_key();
        let raw_value = current_table_info_value.try_as_raw_value()?;

        let txn = Txn::new()
            .when(vec![Compare::with_value(
                raw_key.clone(),
                CompareOp::Equal,
                raw_value.clone(),
            )])
            .and_then(vec![TxnOp::Put(
                raw_key.clone(),
                new_table_info_value.try_as_raw_value()?,
            )])
            .or_else(vec![TxnOp::Get(raw_key.clone())]);

We retrieve the remote value from etcd, deserialize it into the TableInfoValue, and build the transaction with the TableInfoValue serialization value. However, we must ensure it during the serialization, the remote value without changes. This way is problematic, and it's better to build the transaction with the raw value directly.

Implementation challenges

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category Enhancements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants