@@ -317,13 +317,21 @@ private void serialize(OutputStream stream) throws IOException {
317317 private void deserialize (InputStream stream ) throws IOException {
318318 int markerOrSize = ReadWriteIOUtils .readInt (stream );
319319 final boolean structured ;
320+ final boolean hasOccurrenceIndex ;
320321 final int size ;
321- if (markerOrSize == SNAPSHOT_VERSION || markerOrSize == PREVIOUS_SNAPSHOT_VERSION ) {
322+ if (markerOrSize == SNAPSHOT_VERSION ) {
322323 structured = true ;
324+ hasOccurrenceIndex = true ;
325+ size = ReadWriteIOUtils .readInt (stream );
326+ } else if (markerOrSize == PREVIOUS_SNAPSHOT_VERSION ) {
327+ // The first structured snapshot format did not persist nextOccurrenceIndex yet.
328+ structured = true ;
329+ hasOccurrenceIndex = false ;
323330 size = ReadWriteIOUtils .readInt (stream );
324331 } else if (markerOrSize >= 0 ) {
325332 // Snapshots written before structured duration support started with the CQ count.
326333 structured = false ;
334+ hasOccurrenceIndex = false ;
327335 size = markerOrSize ;
328336 } else {
329337 throw new IOException (
@@ -337,7 +345,7 @@ private void deserialize(InputStream stream) throws IOException {
337345 ManagerMessages .EXCEPTION_NEGATIVE_CQ_SNAPSHOT_ENTRY_COUNT_ARG_38750035 , size ));
338346 }
339347 for (int i = 0 ; i < size ; i ++) {
340- CQEntry cqEntry = CQEntry .deserialize (stream , structured );
348+ CQEntry cqEntry = CQEntry .deserialize (stream , structured , hasOccurrenceIndex );
341349 cqMap .put (cqEntry .cqId , cqEntry );
342350 }
343351 }
@@ -527,7 +535,8 @@ private void serialize(OutputStream stream) throws IOException {
527535 ReadWriteIOUtils .write (nextOccurrenceIndex , stream );
528536 }
529537
530- private static CQEntry deserialize (InputStream stream , boolean structured ) throws IOException {
538+ private static CQEntry deserialize (
539+ InputStream stream , boolean structured , boolean hasOccurrenceIndex ) throws IOException {
531540 String cqId = ReadWriteIOUtils .readString (stream );
532541 long everyInterval = ReadWriteIOUtils .readLong (stream );
533542 long boundaryTime = ReadWriteIOUtils .readLong (stream );
@@ -557,7 +566,7 @@ private static CQEntry deserialize(InputStream stream, boolean structured) throw
557566 boolean boundaryExplicit = structured && ReadWriteIOUtils .readBool (stream );
558567 CQState state = CQState .deserialize (ReadWriteIOUtils .readByte (stream ));
559568 long lastExecutionTime = ReadWriteIOUtils .readLong (stream );
560- long nextOccurrenceIndex = structured ? ReadWriteIOUtils .readLong (stream ) : -1 ;
569+ long nextOccurrenceIndex = hasOccurrenceIndex ? ReadWriteIOUtils .readLong (stream ) : -1 ;
561570 return new CQEntry (
562571 cqId ,
563572 everyInterval ,
0 commit comments