tkalkirill commented on code in PR #1280:
URL: https://github.com/apache/ignite-3/pull/1280#discussion_r1015079423
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/snapshot/outgoing/OutgoingSnapshot.java:
##########
@@ -133,39 +141,84 @@ public PartitionKey partitionKey() {
}
/**
- * Freezes the scope of this snapshot.
+ * Freezes the scope of this snapshot. This includes taking snapshot
metadata and opening TX data cursor.
*
* <p>Must be called under snapshot lock.
*/
void freezeScope() {
assert mvOperationsLock.isLocked() : "MV operations lock must be
acquired!";
+ frozenMeta = takeSnapshotMeta();
+
txDataCursor = partition.txStatePartitionStorage().scan();
}
+ private SnapshotMeta takeSnapshotMeta() {
+ long lastAppliedIndex = Math.max(
+ partition.mvPartitionStorage().lastAppliedIndex(),
+ partition.txStatePartitionStorage().lastAppliedIndex()
+ );
+
+ return SnapshotMetaUtils.snapshotMetaAt(lastAppliedIndex, logManager);
+ }
+
+ /**
+ * Returns metadata corresponding to this snapshot.
+ *
+ * @return This snapshot metadata.
+ */
+ public SnapshotMeta meta() {
+ SnapshotMeta meta = frozenMeta;
+
+ assert meta != null : "No snapshot meta yet, probably the snapshot
scope was not yet frozen";
+
+ return meta;
+ }
+
/**
- * Reads a snapshot meta and returns a future with the response.
+ * Reads the snapshot meta and returns a response. Returns {@code null} if
the snapshot is already closed.
*
- * @param metaRequest Meta request.
+ * @param request Meta request.
*/
- SnapshotMetaResponse handleSnapshotMetaRequest(SnapshotMetaRequest
metaRequest) {
- //TODO https://issues.apache.org/jira/browse/IGNITE-17935
+ @Nullable
+ SnapshotMetaResponse handleSnapshotMetaRequest(SnapshotMetaRequest
request) {
Review Comment:
I see that the argument is not used, we need to either remove it or check
that we requested the meta for this particular snapshot.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/snapshot/outgoing/OutgoingSnapshot.java:
##########
@@ -133,39 +141,84 @@ public PartitionKey partitionKey() {
}
/**
- * Freezes the scope of this snapshot.
+ * Freezes the scope of this snapshot. This includes taking snapshot
metadata and opening TX data cursor.
*
* <p>Must be called under snapshot lock.
*/
void freezeScope() {
assert mvOperationsLock.isLocked() : "MV operations lock must be
acquired!";
+ frozenMeta = takeSnapshotMeta();
+
txDataCursor = partition.txStatePartitionStorage().scan();
}
+ private SnapshotMeta takeSnapshotMeta() {
+ long lastAppliedIndex = Math.max(
+ partition.mvPartitionStorage().lastAppliedIndex(),
+ partition.txStatePartitionStorage().lastAppliedIndex()
+ );
+
+ return SnapshotMetaUtils.snapshotMetaAt(lastAppliedIndex, logManager);
+ }
+
+ /**
+ * Returns metadata corresponding to this snapshot.
+ *
+ * @return This snapshot metadata.
+ */
+ public SnapshotMeta meta() {
+ SnapshotMeta meta = frozenMeta;
+
+ assert meta != null : "No snapshot meta yet, probably the snapshot
scope was not yet frozen";
+
+ return meta;
+ }
+
/**
- * Reads a snapshot meta and returns a future with the response.
+ * Reads the snapshot meta and returns a response. Returns {@code null} if
the snapshot is already closed.
*
- * @param metaRequest Meta request.
+ * @param request Meta request.
*/
- SnapshotMetaResponse handleSnapshotMetaRequest(SnapshotMetaRequest
metaRequest) {
- //TODO https://issues.apache.org/jira/browse/IGNITE-17935
+ @Nullable
+ SnapshotMetaResponse handleSnapshotMetaRequest(SnapshotMetaRequest
request) {
+ if (closed) {
+ return logThatAlreadyClosedAndReturnNull();
+ }
+
+ SnapshotMeta meta = frozenMeta;
+
+ assert meta != null : "No snapshot meta yet, probably the snapshot
scope was not yet frozen";
+
+ return MESSAGES_FACTORY.snapshotMetaResponse().meta(meta).build();
+ }
+
+ @Nullable
+ private <T> T logThatAlreadyClosedAndReturnNull() {
Review Comment:
What will happen to the receiver if we return `null`? will he hang?
--
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]