wgtmac commented on code in PR #542:
URL: https://github.com/apache/iceberg-cpp/pull/542#discussion_r2780438762
##########
src/iceberg/transaction.cc:
##########
@@ -428,4 +425,12 @@ Transaction::NewUpdateSnapshotReference() {
return update_ref;
}
+Result<std::shared_ptr<SnapshotManager>> Transaction::NewSnapshotManager() {
+ ICEBERG_ASSIGN_OR_RAISE(std::shared_ptr<SnapshotManager> snapshot_manager,
+ SnapshotManager::Make(shared_from_this()));
+ // SnapshotManager has its own commit logic, so it is not added to the
pending updates.
+ // This differs from the Java implementation.
+ return snapshot_manager;
Review Comment:
```suggestion
// SnapshotManager has its own commit logic, so it is not added to the
pending updates.
return SnapshotManager::Make(shared_from_this());
```
##########
src/iceberg/update/snapshot_manager.cc:
##########
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "iceberg/update/snapshot_manager.h"
+
+#include <memory>
+#include <string>
+
+#include "iceberg/result.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/transaction.h"
+#include "iceberg/update/fast_append.h"
+#include "iceberg/update/set_snapshot.h"
+#include "iceberg/update/update_snapshot_reference.h"
+#include "iceberg/util/macros.h"
+
+namespace iceberg {
+
+Result<std::shared_ptr<SnapshotManager>> SnapshotManager::Make(
+ std::shared_ptr<Transaction> transaction) {
+ ICEBERG_PRECHECK(transaction != nullptr, "Invalid input transaction: null");
+ return std::shared_ptr<SnapshotManager>(new
SnapshotManager(std::move(transaction)));
+}
+
+SnapshotManager::SnapshotManager(std::shared_ptr<Transaction> transaction)
+ : PendingUpdate(transaction) {}
+
+SnapshotManager::~SnapshotManager() = default;
+
+SnapshotManager& SnapshotManager::Cherrypick(int64_t snapshot_id) {
+ // TODO(anyone): Implement cherrypick operation
+ ICEBERG_BUILDER_CHECK(false, "Cherrypick operation not yet implemented");
+ return *this;
+}
+
+SnapshotManager& SnapshotManager::SetCurrentSnapshot(int64_t snapshot_id) {
Review Comment:
If we do not call `CommitIfRefUpdatesExist` to commit previous update,
different updates in this `SnapshotManager` may see stale states. I see that
the main issue is that `Transaction::Commit()` will be called automatically, is
that correct?
##########
src/iceberg/transaction.h:
##########
@@ -105,6 +105,9 @@ class ICEBERG_EXPORT Transaction : public
std::enable_shared_from_this<Transacti
/// and tags) and commit the changes.
Result<std::shared_ptr<UpdateSnapshotReference>>
NewUpdateSnapshotReference();
+ /// \brief Create a new SnapshotManager to manage snapshots.
Review Comment:
I agree with @evindj. We can move `NewSetSnapshot()` and
`NewUpdateSnapshotReference()` to the private scope to mirror the same behavior
of Java `BaseTransaction` class.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]