Skip to content

Commit

Permalink
GEODE-7649 upgrade tests fail when v1.11 is added to geode-old-versio…
Browse files Browse the repository at this point in the history
…ns (apache#4564)

* GEODE-7649 upgrade tests fail when v1.11 is added to geode-old-versions

Geode v1.11 inadvertently changed the form of its saved membership view
by using a FileOutputStream to write it to disk instead of using
an ObjectOutputStream.  The latter writes additional information during
serialization.

Note: there is already a test for this change that will start running
when v1.12 is created and v1.11 is added as a geode-old-version in
settings.gradle.

* corrected serialization in integration test

* flipping equals() check to avoid possible NPE
  • Loading branch information
bschuchardt authored and davebarnes97 committed Jan 22, 2020
1 parent fbf0311 commit bcfa931
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Expand Up @@ -234,7 +234,7 @@ private void populateStateFile(File file, int fileStamp, int ordinal, Object obj
oos.writeInt(fileStamp);
oos.writeInt(ordinal);
oos.flush();
DataOutput dataOutput = new DataOutputStream(fileStream);
DataOutput dataOutput = new DataOutputStream(oos);
DataSerializer.writeObject(object, dataOutput);
fileStream.flush();
}
Expand Down
Expand Up @@ -365,7 +365,7 @@ private void saveView(GMSMembershipView<ID> view) {
oos.writeInt(LOCATOR_FILE_STAMP);
oos.writeInt(Version.getCurrentVersion().ordinal());
oos.flush();
DataOutputStream dataOutputStream = new DataOutputStream(fileStream);
DataOutputStream dataOutputStream = new DataOutputStream(oos);
objectSerializer.writeObject(view, dataOutputStream);
} catch (Exception e) {
logger.warn(
Expand Down Expand Up @@ -442,7 +442,8 @@ boolean recoverFromFile(File file) {
return false;
}

logger.info("Peer locator recovering from {}", file.getAbsolutePath());
logger.info("Peer locator recovering from {} with size {}",
file.getAbsolutePath(), file.length());
try (FileInputStream fileInputStream = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fileInputStream)) {
int stamp = ois.readInt();
Expand All @@ -452,15 +453,21 @@ boolean recoverFromFile(File file) {

int version = ois.readInt();
int currentVersion = Version.getCurrentVersion().ordinal();
DataInputStream input = new DataInputStream(fileInputStream);
if (version != currentVersion) {
DataInputStream input;
if (version == currentVersion) {
input = new DataInputStream(ois);
} else if (version > currentVersion) {
return false;
} else {
Version geodeVersion = Version.fromOrdinalNoThrow((short) version, false);
logger.info("Peer locator found that persistent view was written with version {}",
geodeVersion);
if (version > currentVersion) {
return false;
if (Version.GEODE_1_11_0.equals(geodeVersion)) {
// v1.11 did not create the file with an ObjectOutputStream, so don't use one here
input = new VersionedDataInputStream(fileInputStream, geodeVersion);
} else {
input = new VersionedDataInputStream(ois, geodeVersion);
}
input = new VersionedDataInputStream(ois, geodeVersion);
}

// TBD - services isn't available when we recover from disk so this will throw an NPE
Expand Down

0 comments on commit bcfa931

Please sign in to comment.