Skip to content

Commit f902ab4

Browse files
authored
IGNITE-28516 Use MessageSerializer for DynamicCacheChangeRequest (#13032)
1 parent 79bb465 commit f902ab4

File tree

6 files changed

+126
-59
lines changed

6 files changed

+126
-59
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.apache.ignite.internal.processors.authentication.UserManagementOperationFinishedMessage;
4949
import org.apache.ignite.internal.processors.authentication.UserProposedMessage;
5050
import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage;
51+
import org.apache.ignite.internal.processors.cache.CacheConfigurationEnrichment;
5152
import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
5253
import org.apache.ignite.internal.processors.cache.CacheEvictionEntry;
5354
import org.apache.ignite.internal.processors.cache.CacheInvokeDirectResult;
@@ -56,6 +57,7 @@
5657
import org.apache.ignite.internal.processors.cache.ClientCacheChangeDiscoveryMessage;
5758
import org.apache.ignite.internal.processors.cache.ClientCacheChangeDummyDiscoveryMessage;
5859
import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch;
60+
import org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest;
5961
import org.apache.ignite.internal.processors.cache.ExchangeFailureMessage;
6062
import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo;
6163
import org.apache.ignite.internal.processors.cache.GridCacheReturn;
@@ -628,14 +630,16 @@ public CoreMessagesProvider(Marshaller schemaAwareMarhaller, Marshaller schemaLe
628630
withNoSchema(ChangeCacheEncryptionRequest.class);
629631
withNoSchema(MasterKeyChangeRequest.class);
630632

631-
// [13000 - 13300]: Control, diagnostincs and other messages.
633+
// [13000 - 13300]: Control, configuration, diagnostincs and other messages.
632634
msgIdx = 13000;
633635
withSchema(GridEventStorageMessage.class);
634636
withNoSchema(ChangeGlobalStateMessage.class);
635637
withNoSchema(GridChangeGlobalStateMessageResponse.class);
636638
withSchema(IgniteDiagnosticRequest.class);
637639
withNoSchema(IgniteDiagnosticResponse.class);
638640
withNoSchema(WalStateAckMessage.class);
641+
withNoSchema(CacheConfigurationEnrichment.class);
642+
withNoSchemaResolvedClassLoader(DynamicCacheChangeRequest.class);
639643

640644
assert msgIdx <= MAX_MESSAGE_ID;
641645
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheConfigurationEnrichment.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,35 @@
2020
import java.io.Serializable;
2121
import java.util.Map;
2222
import java.util.Set;
23+
import org.apache.ignite.internal.CoreMessagesProvider;
24+
import org.apache.ignite.internal.Order;
2325
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
2426
import org.apache.ignite.internal.util.typedef.internal.S;
27+
import org.apache.ignite.plugin.extensions.communication.Message;
2528

2629
/**
2730
* Object that contains serialized values for fields marked with {@link org.apache.ignite.configuration.SerializeSeparately}
2831
* in {@link org.apache.ignite.configuration.CacheConfiguration}.
2932
* This object is needed to exchange and store shrinked cache configurations to avoid possible {@link ClassNotFoundException} errors
3033
* during deserialization on nodes where some specific class may not exist.
3134
*/
32-
public class CacheConfigurationEnrichment implements Serializable {
35+
public class CacheConfigurationEnrichment implements Message, Serializable {
3336
/** */
3437
private static final long serialVersionUID = 0L;
3538

3639
/** Field name -> Field serialized value. */
37-
private final Map<String, byte[]> enrichFields;
40+
@Order(0)
41+
Map<String, byte[]> enrichFields;
3842

3943
/** Field name -> Field value class name. */
4044
@GridToStringInclude
41-
private final Map<String, String> fieldClassNames;
45+
@Order(1)
46+
Map<String, String> fieldClassNames;
47+
48+
/** Empty constructor for {@link CoreMessagesProvider}. */
49+
public CacheConfigurationEnrichment() {
50+
// No-op.
51+
}
4252

4353
/**
4454
* Creates a new instance of CacheConfigurationEnrichment.

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ else if (encMgr.masterKeyDigest() != null &&
11611161
req.initiatingNodeId(),
11621162
req.deploymentId(),
11631163
req.encryptionKey(),
1164-
req.encryptionKeyId(),
1164+
req.encryptionKeyId() < 0 ? null : req.encryptionKeyId(),
11651165
req.cacheConfigurationEnrichment()
11661166
);
11671167

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import java.util.Collection;
2121
import java.util.Set;
22-
import org.apache.ignite.IgniteCheckedException;
23-
import org.apache.ignite.internal.MarshallableMessage;
2422
import org.apache.ignite.internal.Order;
2523
import org.apache.ignite.internal.managers.discovery.DiscoCache;
2624
import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
@@ -31,26 +29,22 @@
3129
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
3230
import org.apache.ignite.internal.util.typedef.F;
3331
import org.apache.ignite.internal.util.typedef.internal.S;
34-
import org.apache.ignite.internal.util.typedef.internal.U;
3532
import org.apache.ignite.lang.IgniteUuid;
36-
import org.apache.ignite.marshaller.Marshaller;
33+
import org.apache.ignite.plugin.extensions.communication.Message;
3734
import org.jetbrains.annotations.Nullable;
3835

3936
/**
4037
* Cache change batch.
4138
*/
42-
public class DynamicCacheChangeBatch implements DiscoveryCustomMessage, MarshallableMessage {
39+
public class DynamicCacheChangeBatch implements DiscoveryCustomMessage, Message {
4340
/** Discovery custom message ID. */
4441
@Order(0)
4542
IgniteUuid id;
4643

4744
/** Change requests. */
4845
@GridToStringInclude
49-
Collection<DynamicCacheChangeRequest> reqs;
50-
51-
/** JDK Serialized version of reqs. */
5246
@Order(1)
53-
byte[] requestsBytes;
47+
Collection<DynamicCacheChangeRequest> reqs;
5448

5549
/** Cache updates to be executed on exchange. */
5650
private ExchangeActions exchangeActions;
@@ -172,18 +166,6 @@ public void startCaches(boolean startCaches) {
172166
this.startCaches = startCaches;
173167
}
174168

175-
/** {@inheritDoc} */
176-
@Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException {
177-
if (reqs != null)
178-
requestsBytes = U.marshal(marsh, reqs);
179-
}
180-
181-
/** {@inheritDoc} */
182-
@Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException {
183-
if (requestsBytes != null)
184-
reqs = U.unmarshal(marsh, requestsBytes, clsLdr);
185-
}
186-
187169
/** {@inheritDoc} */
188170
@Override public String toString() {
189171
return S.toString(DynamicCacheChangeBatch.class, this);

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java

Lines changed: 101 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,96 +19,139 @@
1919

2020
import java.io.Serializable;
2121
import java.util.UUID;
22+
import org.apache.ignite.IgniteCheckedException;
2223
import org.apache.ignite.configuration.CacheConfiguration;
2324
import org.apache.ignite.configuration.NearCacheConfiguration;
25+
import org.apache.ignite.internal.CoreMessagesProvider;
2426
import org.apache.ignite.internal.GridKernalContext;
27+
import org.apache.ignite.internal.MarshallableMessage;
28+
import org.apache.ignite.internal.Order;
2529
import org.apache.ignite.internal.processors.query.QuerySchema;
2630
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
2731
import org.apache.ignite.internal.util.typedef.T2;
32+
import org.apache.ignite.internal.util.typedef.internal.U;
2833
import org.apache.ignite.lang.IgniteUuid;
34+
import org.apache.ignite.marshaller.Marshaller;
2935
import org.jetbrains.annotations.Nullable;
3036

3137
/**
3238
* Cache start/stop request.
3339
*/
34-
public class DynamicCacheChangeRequest implements Serializable {
40+
public class DynamicCacheChangeRequest implements MarshallableMessage, Serializable {
3541
/** */
3642
private static final long serialVersionUID = 0L;
3743

3844
/** */
39-
private UUID reqId;
45+
@Order(0)
46+
UUID reqId;
4047

4148
/** Start ID. */
42-
private IgniteUuid deploymentId;
49+
@Order(1)
50+
IgniteUuid deploymentId;
4351

4452
/** Stop cache name. */
4553
@GridToStringExclude
46-
private String cacheName;
54+
@Order(2)
55+
String cacheName;
4756

4857
/** Cache start configuration. */
4958
@GridToStringExclude
50-
private CacheConfiguration startCfg;
59+
private CacheConfiguration<?, ?> startCfg;
60+
61+
/** Bytes of {@link #startCfg}. */
62+
@Order(3)
63+
byte[] cfgBytes;
5164

5265
/** Cache type. */
53-
private CacheType cacheType;
66+
@Order(4)
67+
CacheType cacheType;
5468

5569
/** Near node ID in case if near cache is being started. */
56-
private UUID initiatingNodeId;
70+
@Order(5)
71+
UUID initiatingNodeId;
5772

5873
/** Near cache configuration. */
5974
@GridToStringExclude
60-
private NearCacheConfiguration nearCacheCfg;
75+
private NearCacheConfiguration<?, ?> nearCacheCfg;
76+
77+
/** Bytes of {@link #nearCacheCfg}. */
78+
@Order(6)
79+
byte[] nearCfgBytes;
6180

6281
/** Start only client cache, do not start data nodes. */
63-
private boolean clientStartOnly;
82+
@Order(7)
83+
boolean clientStartOnly;
6484

6585
/** Stop flag. */
66-
private boolean stop;
86+
@Order(8)
87+
boolean stop;
6788

6889
/** Restart flag. */
69-
private boolean restart;
90+
@Order(9)
91+
boolean restart;
7092

7193
/** Finalize update counters flag. */
72-
private boolean finalizePartitionCounters;
94+
@Order(10)
95+
boolean finalizePartitionCounters;
7396

7497
/** Restart operation id. */
75-
private IgniteUuid restartId;
98+
@Order(11)
99+
IgniteUuid restartId;
76100

77101
/** Cache active on start or not*/
78-
private boolean disabledAfterStart;
102+
@Order(12)
103+
boolean disabledAfterStart;
79104

80105
/** Cache data destroy flag. Setting to <code>true</code> will cause removing all cache data.*/
81-
private boolean destroy;
106+
@Order(13)
107+
boolean destroy;
82108

83109
/** Whether cache was created through SQL. */
84-
private boolean sql;
110+
@Order(14)
111+
boolean sql;
85112

86113
/** Fail if exists flag. */
87-
private boolean failIfExists;
114+
@Order(15)
115+
boolean failIfExists;
88116

89117
/** Template configuration flag. */
90-
private boolean template;
118+
@Order(16)
119+
boolean template;
91120

92121
/** Reset lost partitions flag. */
93-
private boolean resetLostPartitions;
122+
@Order(17)
123+
boolean resetLostPartitions;
94124

95125
/** Dynamic schema. */
96-
private QuerySchema schema;
126+
QuerySchema schema;
97127

98-
/** */
99-
private transient boolean locallyConfigured;
128+
/** Bytes of {@link #schema}. */
129+
@Order(18)
130+
byte[] schemaBytes;
131+
132+
/** Is transient. */
133+
private boolean locallyConfigured;
100134

101135
/** Encryption key. */
102-
@Nullable private byte[] encKey;
136+
@Order(19)
137+
@Nullable byte[] encKey;
103138

104139
/** Id of encryption key. */
105-
@Nullable private Integer encKeyId;
140+
@Order(20)
141+
int encKeyId;
106142

107143
/** Master key digest. */
108-
@Nullable private byte[] masterKeyDigest;
144+
@Order(21)
145+
@Nullable byte[] masterKeyDigest;
109146

110147
/** Cache configuration enrichment. */
111-
private CacheConfigurationEnrichment cacheCfgEnrichment;
148+
@Order(22)
149+
CacheConfigurationEnrichment cacheCfgEnrichment;
150+
151+
/** Empty constructor for {@link CoreMessagesProvider}. */
152+
public DynamicCacheChangeRequest() {
153+
// No-op.
154+
}
112155

113156
/**
114157
* @param reqId Unique request ID.
@@ -123,6 +166,32 @@ public DynamicCacheChangeRequest(UUID reqId, String cacheName, UUID initiatingNo
123166
this.initiatingNodeId = initiatingNodeId;
124167
}
125168

169+
/** {@inheritDoc} */
170+
@Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException {
171+
cfgBytes = U.marshal(marsh, startCfg);
172+
173+
if (nearCacheCfg != null)
174+
nearCfgBytes = U.marshal(marsh, nearCacheCfg);
175+
176+
if (schema != null)
177+
schemaBytes = U.marshal(marsh, schema);
178+
}
179+
180+
/** {@inheritDoc} */
181+
@Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException {
182+
startCfg = U.unmarshal(marsh, cfgBytes, clsLdr);
183+
184+
if (nearCfgBytes != null)
185+
nearCacheCfg = U.unmarshal(marsh, nearCfgBytes, clsLdr);
186+
187+
if (schemaBytes != null)
188+
schema = U.unmarshal(marsh, schemaBytes, clsLdr);
189+
190+
cfgBytes = null;
191+
nearCfgBytes = null;
192+
schemaBytes = null;
193+
}
194+
126195
/**
127196
* @param ctx Context.
128197
* @param cacheName Cache name.
@@ -338,28 +407,28 @@ public UUID initiatingNodeId() {
338407
/**
339408
* @return Near cache configuration.
340409
*/
341-
public NearCacheConfiguration nearCacheConfiguration() {
410+
public NearCacheConfiguration<?, ?> nearCacheConfiguration() {
342411
return nearCacheCfg;
343412
}
344413

345414
/**
346415
* @param nearCacheCfg Near cache configuration.
347416
*/
348-
public void nearCacheConfiguration(NearCacheConfiguration nearCacheCfg) {
417+
public void nearCacheConfiguration(NearCacheConfiguration<?, ?> nearCacheCfg) {
349418
this.nearCacheCfg = nearCacheCfg;
350419
}
351420

352421
/**
353422
* @return Cache configuration.
354423
*/
355-
public CacheConfiguration startCacheConfiguration() {
424+
public CacheConfiguration<?, ?> startCacheConfiguration() {
356425
return startCfg;
357426
}
358427

359428
/**
360429
* @param startCfg Cache configuration.
361430
*/
362-
public void startCacheConfiguration(CacheConfiguration startCfg) {
431+
public void startCacheConfiguration(CacheConfiguration<?, ?> startCfg) {
363432
this.startCfg = startCfg;
364433

365434
if (startCfg.getNearConfiguration() != null)
@@ -485,14 +554,14 @@ public void encryptionKey(@Nullable byte[] encKey) {
485554
*
486555
* @param encKeyId Encryption key id.
487556
*/
488-
public void encryptionKeyId(@Nullable Integer encKeyId) {
557+
public void encryptionKeyId(int encKeyId) {
489558
this.encKeyId = encKeyId;
490559
}
491560

492561
/**
493562
* @return Encryption key id.
494563
*/
495-
@Nullable public Integer encryptionKeyId() {
564+
@Nullable public int encryptionKeyId() {
496565
return encKeyId;
497566
}
498567

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5087,7 +5087,9 @@ private DynamicCacheChangeRequest prepareCacheChangeRequest(
50875087

50885088
req.encryptionKey(encKey);
50895089

5090-
req.encryptionKeyId(encKeyId);
5090+
assert encKeyId == null || encKeyId >= 0;
5091+
5092+
req.encryptionKeyId(encKeyId == null ? -1 : encKeyId);
50915093

50925094
req.restartId(restartId);
50935095

0 commit comments

Comments
 (0)