@@ -7195,8 +7195,8 @@ func TestEntries(t *testing.T) {
7195
7195
}},
7196
7196
// Case 5: Get a single entry from cache.
7197
7197
{lo : indexes [5 ], hi : indexes [6 ], expResultCount : 1 , expCacheCount : 1 , setup : nil },
7198
- // Case 6: Use MaxUint64 instead of 0 for maxBytes .
7199
- {lo : indexes [5 ], hi : indexes [9 ], maxBytes : math . MaxUint64 , expResultCount : 4 , expCacheCount : 4 , setup : nil },
7198
+ // Case 6: Get range without size limitation. (Like case 4, without truncating) .
7199
+ {lo : indexes [5 ], hi : indexes [9 ], expResultCount : 4 , expCacheCount : 4 , setup : nil },
7200
7200
// Case 7: maxBytes is set low so only a single value should be
7201
7201
// returned.
7202
7202
{lo : indexes [5 ], hi : indexes [9 ], maxBytes : 1 , expResultCount : 1 , expCacheCount : 1 , setup : nil },
@@ -7242,7 +7242,10 @@ func TestEntries(t *testing.T) {
7242
7242
if tc .setup != nil {
7243
7243
tc .setup ()
7244
7244
}
7245
- cacheEntries , _ , _ := repl .store .raftEntryCache .getEntries (nil , rangeID , tc .lo , tc .hi , tc .maxBytes )
7245
+ if tc .maxBytes == 0 {
7246
+ tc .maxBytes = math .MaxUint64
7247
+ }
7248
+ cacheEntries , _ , _ , hitLimit := repl .store .raftEntryCache .getEntries (nil , rangeID , tc .lo , tc .hi , tc .maxBytes )
7246
7249
if len (cacheEntries ) != tc .expCacheCount {
7247
7250
t .Errorf ("%d: expected cache count %d, got %d" , i , tc .expCacheCount , len (cacheEntries ))
7248
7251
}
@@ -7258,12 +7261,17 @@ func TestEntries(t *testing.T) {
7258
7261
}
7259
7262
if len (ents ) != tc .expResultCount {
7260
7263
t .Errorf ("%d: expected %d entries, got %d" , i , tc .expResultCount , len (ents ))
7264
+ } else if tc .expResultCount > 0 {
7265
+ expHitLimit := ents [len (ents )- 1 ].Index < tc .hi - 1
7266
+ if hitLimit != expHitLimit {
7267
+ t .Errorf ("%d: unexpected hit limit: %t" , i , hitLimit )
7268
+ }
7261
7269
}
7262
7270
}
7263
7271
7264
7272
// Case 23: Lo must be less than or equal to hi.
7265
7273
repl .mu .Lock ()
7266
- if _ , err := repl .raftEntriesLocked (indexes [9 ], indexes [5 ], 0 ); err == nil {
7274
+ if _ , err := repl .raftEntriesLocked (indexes [9 ], indexes [5 ], math . MaxUint64 ); err == nil {
7267
7275
t .Errorf ("23: error expected, got none" )
7268
7276
}
7269
7277
repl .mu .Unlock ()
@@ -7276,21 +7284,34 @@ func TestEntries(t *testing.T) {
7276
7284
7277
7285
repl .mu .Lock ()
7278
7286
defer repl .mu .Unlock ()
7279
- if _ , err := repl .raftEntriesLocked (indexes [5 ], indexes [9 ], 0 ); err == nil {
7287
+ if _ , err := repl .raftEntriesLocked (indexes [5 ], indexes [9 ], math . MaxUint64 ); err == nil {
7280
7288
t .Errorf ("24: error expected, got none" )
7281
7289
}
7282
7290
7283
- // Case 25: don't hit the gap due to maxBytes.
7284
- ents , err := repl .raftEntriesLocked (indexes [5 ], indexes [9 ], 1 )
7285
- if err != nil {
7286
- t .Errorf ("25: expected no error, got %s" , err )
7291
+ // Case 25a: don't hit the gap due to maxBytes, cache populated.
7292
+ {
7293
+ ents , err := repl .raftEntriesLocked (indexes [5 ], indexes [9 ], 1 )
7294
+ if err != nil {
7295
+ t .Errorf ("25: expected no error, got %s" , err )
7296
+ }
7297
+ if len (ents ) != 1 {
7298
+ t .Errorf ("25: expected 1 entry, got %d" , len (ents ))
7299
+ }
7287
7300
}
7288
- if len (ents ) != 1 {
7289
- t .Errorf ("25: expected 1 entry, got %d" , len (ents ))
7301
+ // Case 25b: don't hit the gap due to maxBytes, cache cleared.
7302
+ {
7303
+ repl .store .raftEntryCache .delEntries (rangeID , indexes [5 ], indexes [5 ]+ 1 )
7304
+ ents , err := repl .raftEntriesLocked (indexes [5 ], indexes [9 ], 1 )
7305
+ if err != nil {
7306
+ t .Errorf ("25: expected no error, got %s" , err )
7307
+ }
7308
+ if len (ents ) != 1 {
7309
+ t .Errorf ("25: expected 1 entry, got %d" , len (ents ))
7310
+ }
7290
7311
}
7291
7312
7292
7313
// Case 26: don't hit the gap due to truncation.
7293
- if _ , err := repl .raftEntriesLocked (indexes [4 ], indexes [9 ], 0 ); err != raft .ErrCompacted {
7314
+ if _ , err := repl .raftEntriesLocked (indexes [4 ], indexes [9 ], math . MaxUint64 ); err != raft .ErrCompacted {
7294
7315
t .Errorf ("26: expected error %s , got %s" , raft .ErrCompacted , err )
7295
7316
}
7296
7317
}
0 commit comments