Skip to content

Commit e024705

Browse files
authored
IGNITE-28511 Use MessageSerializer for SnapshotMetadata and WALPointer (#13076)
1 parent bf1327c commit e024705

4 files changed

Lines changed: 65 additions & 43 deletions

File tree

modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotFilesFailureMessage;
148148
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotFilesRequestMessage;
149149
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotHandlerResult;
150+
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotMetadata;
150151
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotMetadataResponse;
151152
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotOperationEndRequest;
152153
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotOperationRequest;
@@ -155,6 +156,7 @@
155156
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotRestoreOperationResponse;
156157
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotRestoreStartRequest;
157158
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotStartDiscoveryMessage;
159+
import org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer;
158160
import org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest;
159161
import org.apache.ignite.internal.processors.cache.query.GridCacheQueryResponse;
160162
import org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery;
@@ -343,6 +345,7 @@ public CoreMessagesProvider(Marshaller dfltMarsh, Marshaller schemaAwareMarsh, C
343345
withNoSchema(CacheVersionedValue.class);
344346
withNoSchema(GridCacheVersion.class);
345347
withNoSchema(GridCacheVersionEx.class);
348+
withNoSchema(WALPointer.class);
346349

347350
// [5700 - 5900]: Discovery originated messages.
348351
msgIdx = 5700;
@@ -384,6 +387,7 @@ public CoreMessagesProvider(Marshaller dfltMarsh, Marshaller schemaAwareMarsh, C
384387
withNoSchema(SnapshotPartitionsVerifyHandlerResponse.class);
385388
withNoSchema(SnapshotRestoreOperationResponse.class);
386389
withNoSchema(SnapshotMetadataResponse.class);
390+
withNoSchema(SnapshotMetadata.class);
387391
withNoSchema(SnapshotCheckPartitionHashesResponse.class);
388392
withNoSchema(SnapshotCheckHandlersResponse.class);
389393
withNoSchema(SnapshotFilesRequestMessage.class);

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadata.java

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,94 +30,119 @@
3030
import java.util.Objects;
3131
import java.util.Set;
3232
import java.util.UUID;
33+
import org.apache.ignite.internal.Order;
3334
import org.apache.ignite.internal.pagemem.wal.record.delta.ClusterSnapshotRecord;
3435
import org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId;
3536
import org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer;
3637
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
3738
import org.apache.ignite.internal.util.typedef.F;
3839
import org.apache.ignite.internal.util.typedef.internal.S;
3940
import org.apache.ignite.internal.util.typedef.internal.U;
41+
import org.apache.ignite.plugin.extensions.communication.Message;
42+
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
4043
import org.jetbrains.annotations.Nullable;
4144

4245
/**
4346
* Snapshot metadata file.
4447
* <p>
4548
* All changes must be made with the respect of RU rules.
4649
*/
47-
public class SnapshotMetadata implements Serializable {
50+
public class SnapshotMetadata implements Message, Serializable {
4851
/** Serial version uid. */
4952
private static final long serialVersionUID = 0L;
5053

5154
/** Unique snapshot request id. */
52-
private final UUID rqId;
55+
@Order(0)
56+
UUID rqId;
5357

5458
/** Snapshot name. */
5559
@GridToStringInclude
56-
private final String snpName;
60+
@Order(1)
61+
String snpName;
5762

5863
/** Consistent id of a node to which this metadata relates. */
5964
@GridToStringInclude
60-
private final String consId;
65+
@Order(2)
66+
String consId;
6167

6268
/**
6369
* Directory related to the current consistent node id on which partition files are stored.
6470
* For some of the cases, consId doesn't equal the directory name.
6571
*/
66-
private final String folderName;
72+
@Order(3)
73+
String folderName;
6774

6875
/**
6976
* If {@code true} then compress partition files.
7077
* This shouldn't be confused with {@link SnapshotMetadata#comprGrpIds} which represents how Ignite keeps data in memory pages
7178
* while {@link SnapshotMetadata#comprParts} represents how dump files are stored on disk.
7279
*/
73-
private final boolean comprParts;
80+
@Order(4)
81+
boolean comprParts;
7482

7583
/** Page size of stored snapshot data. */
76-
private final int pageSize;
84+
@Order(5)
85+
int pageSize;
7786

7887
/** The list of cache groups ids which were included into snapshot. */
7988
@GridToStringInclude
80-
private final List<Integer> grpIds;
89+
@Order(6)
90+
List<Integer> grpIds;
8191

8292
/** The set of affected by snapshot baseline nodes. */
8393
@GridToStringInclude
84-
private final Set<String> bltNodes;
94+
@Order(7)
95+
Set<String> bltNodes;
8596

8697
/** WAL pointer to {@link ClusterSnapshotRecord} if exists. */
87-
private final @Nullable WALPointer snpRecPtr;
98+
@Order(8)
99+
@Nullable WALPointer snpRecPtr;
88100

89101
/**
90102
* Map of cache group partitions from which snapshot has been taken on the local node. This map can be empty
91103
* since for instance, due to the node filter there is no cache data on node.
92104
*/
93105
@GridToStringInclude
94-
private transient Map<Integer, Set<Integer>> locParts = new HashMap<>();
106+
@Order(9)
107+
transient Map<Integer, Set<Integer>> locParts = new HashMap<>();
95108

96109
/** Master key digest for encrypted caches. */
97110
@GridToStringInclude
98-
@Nullable private final byte[] masterKeyDigest;
111+
@Order(10)
112+
@Nullable byte[] masterKeyDigest;
99113

100114
/** Warnings occurred at snapshot creation. */
101115
@GridToStringInclude
102-
@Nullable private List<String> warnings;
116+
@Order(11)
117+
@Nullable List<String> warnings;
103118

104119
/** Creation timestamp in milliseconds since Unix epoch. */
105-
private long snapshotTime;
120+
@Order(12)
121+
long snapshotTime;
106122

107123
/** */
108-
private transient Set<Integer> comprGrpIds;
124+
@Order(13)
125+
@Nullable transient Set<Integer> comprGrpIds;
109126

110127
/** */
111128
private boolean hasComprGrps;
112129

113130
/** If {@code true} snapshot only primary copies of partitions. */
114-
private boolean onlyPrimary;
131+
@Order(14)
132+
boolean onlyPrimary;
115133

116134
/** If {@code true} cache group dump stored. */
117-
private boolean dump;
135+
@Order(15)
136+
boolean dump;
118137

119138
/** Encryption key. */
120-
private @Nullable byte[] encKey;
139+
@Order(16)
140+
@Nullable byte[] encKey;
141+
142+
/** Empty constructor for a {@link MessageFactory}. */
143+
public SnapshotMetadata() {
144+
// No-op.
145+
}
121146

122147
/**
123148
* @param rqId Unique request id.

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataResponse.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,15 @@
1818
package org.apache.ignite.internal.processors.cache.persistence.snapshot;
1919

2020
import java.util.List;
21-
import org.apache.ignite.IgniteCheckedException;
22-
import org.apache.ignite.internal.MarshallableMessage;
2321
import org.apache.ignite.internal.Order;
24-
import org.apache.ignite.internal.util.typedef.internal.U;
25-
import org.apache.ignite.marshaller.Marshaller;
22+
import org.apache.ignite.plugin.extensions.communication.Message;
2623
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
2724

2825
/** */
29-
public class SnapshotMetadataResponse implements MarshallableMessage {
26+
public class SnapshotMetadataResponse implements Message {
3027
/** */
3128
@Order(0)
32-
byte[] metadataBytes;
33-
34-
/** */
35-
private List<SnapshotMetadata> metadata;
29+
List<SnapshotMetadata> metadata;
3630

3731
/** Default constructor for {@link MessageFactory}. */
3832
public SnapshotMetadataResponse() {
@@ -48,16 +42,4 @@ public SnapshotMetadataResponse(List<SnapshotMetadata> metadata) {
4842
public List<SnapshotMetadata> metadata() {
4943
return metadata;
5044
}
51-
52-
/** {@inheritDoc} */
53-
@Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException {
54-
metadataBytes = U.marshal(marsh, metadata);
55-
}
56-
57-
/** {@inheritDoc} */
58-
@Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException {
59-
if (metadataBytes != null)
60-
metadata = U.unmarshal(marsh, metadataBytes, clsLdr);
61-
}
62-
6345
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/WALPointer.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,38 @@
1818
package org.apache.ignite.internal.processors.cache.persistence.wal;
1919

2020
import java.io.Serializable;
21+
import org.apache.ignite.internal.Order;
2122
import org.apache.ignite.internal.util.typedef.internal.S;
23+
import org.apache.ignite.plugin.extensions.communication.Message;
24+
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
2225
import org.jetbrains.annotations.NotNull;
2326

2427
/**
2528
* File WAL pointer.
2629
*/
27-
public class WALPointer implements Serializable, Comparable<WALPointer> {
30+
public class WALPointer implements Message, Comparable<WALPointer>, Serializable {
2831
/** Serial version uid. */
2932
private static final long serialVersionUID = 0L;
3033

3134
/** Pointer serialized size. */
3235
public static final int POINTER_SIZE = 16;
3336

3437
/** Absolute WAL segment file index (incrementing counter) */
35-
private final long idx;
38+
@Order(0)
39+
long idx;
3640

3741
/** */
38-
private final int fileOff;
42+
@Order(1)
43+
int fileOff;
3944

4045
/** Written record length */
41-
private int len;
46+
@Order(2)
47+
int len;
48+
49+
/** Empty constructor for a {@link MessageFactory}. */
50+
public WALPointer() {
51+
// No-op.
52+
}
4253

4354
/**
4455
* @param idx Absolute WAL segment file index (incremental counter).

0 commit comments

Comments
 (0)