Skip to content

Commit bce1f44

Browse files
HCD-153 C* 3.x don't like the trailing sha in the version over gossip (VersionedValue)
1 parent 09190f8 commit bce1f44

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/java/org/apache/cassandra/gms/EndpointState.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424

2525
import javax.annotation.Nullable;
2626

27+
import com.google.common.annotations.VisibleForTesting;
2728
import org.slf4j.Logger;
2829
import org.slf4j.LoggerFactory;
2930

3031
import org.apache.cassandra.db.TypeSizes;
3132
import org.apache.cassandra.io.IVersionedSerializer;
3233
import org.apache.cassandra.io.util.DataInputPlus;
3334
import org.apache.cassandra.io.util.DataOutputPlus;
35+
import org.apache.cassandra.net.MessagingService;
3436
import org.apache.cassandra.utils.CassandraVersion;
3537

3638
/**
@@ -265,7 +267,7 @@ public void serialize(EndpointState epState, DataOutputPlus out, int version) th
265267
out.writeInt(states.size());
266268
for (Map.Entry<ApplicationState, VersionedValue> state : states)
267269
{
268-
VersionedValue value = state.getValue();
270+
VersionedValue value = filterValue(state.getKey(), state.getValue(), version);
269271
out.writeInt(state.getKey().ordinal());
270272
VersionedValue.serializer.serialize(value, out, version);
271273
}
@@ -294,10 +296,19 @@ public long serializedSize(EndpointState epState, int version)
294296
size += TypeSizes.sizeof(states.size());
295297
for (Map.Entry<ApplicationState, VersionedValue> state : states)
296298
{
297-
VersionedValue value = state.getValue();
299+
VersionedValue value = filterValue(state.getKey(), state.getValue(), version);
298300
size += TypeSizes.sizeof(state.getKey().ordinal());
299301
size += VersionedValue.serializer.serializedSize(value, version);
300302
}
301303
return size;
302304
}
305+
306+
@VisibleForTesting
307+
static VersionedValue filterValue(ApplicationState state, VersionedValue value, int version)
308+
{
309+
// CC versions come with a sha suffix that C* 3.x nodes cannot parse
310+
return version < MessagingService.VERSION_40 && ApplicationState.RELEASE_VERSION == state
311+
? VersionedValue.unsafeMakeVersionedValue(value.value.replaceFirst("-[0-9a-f]{7,40}$", ""), value.version)
312+
: value;
313+
}
303314
}

test/unit/org/apache/cassandra/gms/EndpointStateTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.cassandra.gms;
2020

21+
import java.io.IOException;
2122
import java.net.InetAddress;
2223
import java.net.UnknownHostException;
2324
import java.util.Collections;
@@ -33,7 +34,9 @@
3334

3435
import org.apache.cassandra.config.DatabaseDescriptor;
3536
import org.apache.cassandra.dht.Token;
36-
import org.apache.cassandra.locator.InetAddressAndPort;
37+
import org.apache.cassandra.io.util.DataInputBuffer;
38+
import org.apache.cassandra.io.util.DataOutputBuffer;
39+
import org.apache.cassandra.net.MessagingService;
3740

3841
import static org.junit.Assert.assertEquals;
3942
import static org.junit.Assert.assertTrue;
@@ -166,4 +169,34 @@ public void run()
166169
assertTrue(values.containsKey(ApplicationState.INTERNAL_IP));
167170
assertTrue(values.containsKey(ApplicationState.HOST_ID));
168171
}
172+
173+
@Test
174+
public void testCCReleaseVersion() throws IOException
175+
{
176+
String versionString = "4.0.11.0-0b982c438bfc";
177+
String c3safeVersionString = "4.0.11.0";
178+
VersionedValue releaseVersion = valueFactory.releaseVersion(versionString);
179+
180+
assertEquals(versionString, EndpointStateSerializer.filterValue(ApplicationState.RELEASE_VERSION, releaseVersion, MessagingService.VERSION_40).value);
181+
assertEquals(c3safeVersionString, EndpointStateSerializer.filterValue(ApplicationState.RELEASE_VERSION, releaseVersion, MessagingService.VERSION_3014).value);
182+
183+
HeartBeatState hb = new HeartBeatState(0);
184+
EndpointState state = new EndpointState(hb);
185+
Map<ApplicationState, VersionedValue> states = new EnumMap<>(ApplicationState.class);
186+
states.put(ApplicationState.RELEASE_VERSION, releaseVersion);
187+
state.addApplicationStates(states);
188+
assertEquals(versionString, state.getReleaseVersion().toString());
189+
190+
DataOutputBuffer buffer = new DataOutputBuffer();
191+
EndpointState.serializer.serialize(state, buffer, MessagingService.VERSION_40);
192+
DataInputBuffer input = new DataInputBuffer(buffer.buffer(), false);
193+
EndpointState deserializedCurrent = EndpointState.serializer.deserialize(input, MessagingService.VERSION_40);
194+
assertEquals(versionString, deserializedCurrent.getApplicationState(ApplicationState.RELEASE_VERSION).value);
195+
196+
buffer = new DataOutputBuffer();
197+
EndpointState.serializer.serialize(state, buffer, MessagingService.VERSION_3014);
198+
input = new DataInputBuffer(buffer.buffer(), false);
199+
EndpointState deserializedOld = EndpointState.serializer.deserialize(input, MessagingService.VERSION_3014);
200+
assertEquals(c3safeVersionString, deserializedOld.getApplicationState(ApplicationState.RELEASE_VERSION).value);
201+
}
169202
}

0 commit comments

Comments
 (0)