Skip to content

Commit

Permalink
Merge pull request #1271 from nicktrav/nickt.sep-key
Browse files Browse the repository at this point in the history
base: add `InternalKeyKindSeparator`
  • Loading branch information
nicktrav authored Sep 16, 2021
2 parents 3f0c125 + 971533d commit 305d298
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 162 deletions.
304 changes: 152 additions & 152 deletions get_iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetIter(t *testing.T) {
{
description: "empty: an empty version",
queries: []string{
"abc.MAX.101 ErrNotFound",
"abc.SEPARATOR.101 ErrNotFound",
},
},

Expand All @@ -59,21 +59,21 @@ func TestGetIter(t *testing.T) {
},
},
queries: []string{
"aaa.MAX.105 ErrNotFound",
"cat.MAX.105 b",
"hat.MAX.105 ErrNotFound",
"mat.MAX.105 e",
"the.MAX.108 g",
"the.MAX.107 g",
"the.MAX.106 ErrNotFound",
"the.MAX.105 d",
"the.MAX.104 d",
"the.MAX.104 d",
"the.MAX.103 a",
"the.MAX.102 a",
"the.MAX.101 a",
"the.MAX.100 ErrNotFound",
"zzz.MAX.105 ErrNotFound",
"aaa.SEPARATOR.105 ErrNotFound",
"cat.SEPARATOR.105 b",
"hat.SEPARATOR.105 ErrNotFound",
"mat.SEPARATOR.105 e",
"the.SEPARATOR.108 g",
"the.SEPARATOR.107 g",
"the.SEPARATOR.106 ErrNotFound",
"the.SEPARATOR.105 d",
"the.SEPARATOR.104 d",
"the.SEPARATOR.104 d",
"the.SEPARATOR.103 a",
"the.SEPARATOR.102 a",
"the.SEPARATOR.101 a",
"the.SEPARATOR.100 ErrNotFound",
"zzz.SEPARATOR.105 ErrNotFound",
},
},

Expand Down Expand Up @@ -118,45 +118,45 @@ func TestGetIter(t *testing.T) {
},
},
queries: []string{
"aaa.MAX.105 ErrNotFound",
"awk.MAX.135 w",
"awk.MAX.125 w",
"awk.MAX.115 w",
"awk.MAX.105 ErrNotFound",
"cat.MAX.135 ErrNotFound",
"cat.MAX.125 ErrNotFound",
"cat.MAX.115 x",
"cat.MAX.105 b",
"man.MAX.135 G",
"man.MAX.125 ErrNotFound",
"man.MAX.115 y",
"man.MAX.105 ErrNotFound",
"on_.MAX.135 c",
"on_.MAX.125 c",
"on_.MAX.115 c",
"on_.MAX.105 c",
"the.MAX.135 F",
"the.MAX.127 F",
"the.MAX.126 F",
"the.MAX.125 ErrNotFound",
"the.MAX.122 ErrNotFound",
"the.MAX.121 ErrNotFound",
"the.MAX.120 g",
"the.MAX.115 g",
"the.MAX.114 g",
"the.MAX.111 g",
"the.MAX.110 g",
"the.MAX.108 g",
"the.MAX.107 g",
"the.MAX.106 ErrNotFound",
"the.MAX.105 d",
"the.MAX.104 d",
"the.MAX.104 d",
"the.MAX.103 a",
"the.MAX.102 a",
"the.MAX.101 a",
"the.MAX.100 ErrNotFound",
"zzz.MAX.105 ErrNotFound",
"aaa.SEPARATOR.105 ErrNotFound",
"awk.SEPARATOR.135 w",
"awk.SEPARATOR.125 w",
"awk.SEPARATOR.115 w",
"awk.SEPARATOR.105 ErrNotFound",
"cat.SEPARATOR.135 ErrNotFound",
"cat.SEPARATOR.125 ErrNotFound",
"cat.SEPARATOR.115 x",
"cat.SEPARATOR.105 b",
"man.SEPARATOR.135 G",
"man.SEPARATOR.125 ErrNotFound",
"man.SEPARATOR.115 y",
"man.SEPARATOR.105 ErrNotFound",
"on_.SEPARATOR.135 c",
"on_.SEPARATOR.125 c",
"on_.SEPARATOR.115 c",
"on_.SEPARATOR.105 c",
"the.SEPARATOR.135 F",
"the.SEPARATOR.127 F",
"the.SEPARATOR.126 F",
"the.SEPARATOR.125 ErrNotFound",
"the.SEPARATOR.122 ErrNotFound",
"the.SEPARATOR.121 ErrNotFound",
"the.SEPARATOR.120 g",
"the.SEPARATOR.115 g",
"the.SEPARATOR.114 g",
"the.SEPARATOR.111 g",
"the.SEPARATOR.110 g",
"the.SEPARATOR.108 g",
"the.SEPARATOR.107 g",
"the.SEPARATOR.106 ErrNotFound",
"the.SEPARATOR.105 d",
"the.SEPARATOR.104 d",
"the.SEPARATOR.104 d",
"the.SEPARATOR.103 a",
"the.SEPARATOR.102 a",
"the.SEPARATOR.101 a",
"the.SEPARATOR.100 ErrNotFound",
"zzz.SEPARATOR.105 ErrNotFound",
},
},

Expand Down Expand Up @@ -201,47 +201,47 @@ func TestGetIter(t *testing.T) {
},
},
queries: []string{
"a_______.MAX.999 ErrNotFound",
"aardvark.MAX.999 a1",
"aardvark.MAX.102 a1",
"aardvark.MAX.101 a1",
"aardvark.MAX.100 ErrNotFound",
"alpaca__.MAX.999 a2",
"alpaca__.MAX.200 ErrNotFound",
"anteater.MAX.999 a3",
"anteater.MAX.302 a3",
"anteater.MAX.301 a3",
"anteater.MAX.300 ErrNotFound",
"anteater.MAX.000 ErrNotFound",
"b_______.MAX.999 ErrNotFound",
"baboon__.MAX.999 b3",
"baboon__.MAX.302 b3",
"baboon__.MAX.301 ErrNotFound",
"baboon__.MAX.202 ErrNotFound",
"baboon__.MAX.201 b1",
"baboon__.MAX.102 b1",
"baboon__.MAX.101 ErrNotFound",
"bear____.MAX.999 ErrNotFound",
"bear____.MAX.500 b4",
"bear____.MAX.000 ErrNotFound",
"buffalo_.MAX.999 b6",
"buffalo_.MAX.603 b6",
"buffalo_.MAX.602 b6",
"buffalo_.MAX.601 B1",
"buffalo_.MAX.104 B1",
"buffalo_.MAX.103 B1",
"buffalo_.MAX.102 ErrNotFound",
"buffalo_.MAX.000 ErrNotFound",
"c_______.MAX.999 ErrNotFound",
"chipmunk.MAX.999 c2",
"chipmunk.MAX.205 c2",
"chipmunk.MAX.204 c2",
"chipmunk.MAX.203 c1",
"chipmunk.MAX.105 c1",
"chipmunk.MAX.104 c1",
"chipmunk.MAX.103 ErrNotFound",
"chipmunk.MAX.000 ErrNotFound",
"d_______.MAX.999 ErrNotFound",
"a_______.SEPARATOR.999 ErrNotFound",
"aardvark.SEPARATOR.999 a1",
"aardvark.SEPARATOR.102 a1",
"aardvark.SEPARATOR.101 a1",
"aardvark.SEPARATOR.100 ErrNotFound",
"alpaca__.SEPARATOR.999 a2",
"alpaca__.SEPARATOR.200 ErrNotFound",
"anteater.SEPARATOR.999 a3",
"anteater.SEPARATOR.302 a3",
"anteater.SEPARATOR.301 a3",
"anteater.SEPARATOR.300 ErrNotFound",
"anteater.SEPARATOR.000 ErrNotFound",
"b_______.SEPARATOR.999 ErrNotFound",
"baboon__.SEPARATOR.999 b3",
"baboon__.SEPARATOR.302 b3",
"baboon__.SEPARATOR.301 ErrNotFound",
"baboon__.SEPARATOR.202 ErrNotFound",
"baboon__.SEPARATOR.201 b1",
"baboon__.SEPARATOR.102 b1",
"baboon__.SEPARATOR.101 ErrNotFound",
"bear____.SEPARATOR.999 ErrNotFound",
"bear____.SEPARATOR.500 b4",
"bear____.SEPARATOR.000 ErrNotFound",
"buffalo_.SEPARATOR.999 b6",
"buffalo_.SEPARATOR.603 b6",
"buffalo_.SEPARATOR.602 b6",
"buffalo_.SEPARATOR.601 B1",
"buffalo_.SEPARATOR.104 B1",
"buffalo_.SEPARATOR.103 B1",
"buffalo_.SEPARATOR.102 ErrNotFound",
"buffalo_.SEPARATOR.000 ErrNotFound",
"c_______.SEPARATOR.999 ErrNotFound",
"chipmunk.SEPARATOR.999 c2",
"chipmunk.SEPARATOR.205 c2",
"chipmunk.SEPARATOR.204 c2",
"chipmunk.SEPARATOR.203 c1",
"chipmunk.SEPARATOR.105 c1",
"chipmunk.SEPARATOR.104 c1",
"chipmunk.SEPARATOR.103 ErrNotFound",
"chipmunk.SEPARATOR.000 ErrNotFound",
"d_______.SEPARATOR.999 ErrNotFound",
},
},

Expand Down Expand Up @@ -313,62 +313,62 @@ func TestGetIter(t *testing.T) {
},
},
queries: []string{
"a________.MAX.999 ErrNotFound",
"alfalfa__.MAX.520 p1",
"alfalfa__.MAX.510 p1",
"alfalfa__.MAX.500 r1",
"alfalfa__.MAX.400 u1",
"alfalfa__.MAX.300 ErrNotFound",
"asparagus.MAX.520 q3",
"asparagus.MAX.510 p2",
"asparagus.MAX.500 r2",
"asparagus.MAX.400 ErrNotFound",
"asparagus.MAX.300 ErrNotFound",
"arugula__.MAX.520 r3",
"arugula__.MAX.510 r3",
"arugula__.MAX.500 r3",
"arugula__.MAX.400 ErrNotFound",
"arugula__.MAX.300 ErrNotFound",
"beans____.MAX.520 q4",
"beans____.MAX.510 s2",
"beans____.MAX.500 s2",
"beans____.MAX.400 ErrNotFound",
"beans____.MAX.300 ErrNotFound",
"bokchoy__.MAX.520 ErrNotFound",
"bokchoy__.MAX.510 ErrNotFound",
"bokchoy__.MAX.500 ErrNotFound",
"bokchoy__.MAX.400 u2",
"bokchoy__.MAX.300 ErrNotFound",
"broccoli_.MAX.520 q5",
"broccoli_.MAX.510 s4",
"broccoli_.MAX.500 s4",
"broccoli_.MAX.400 ErrNotFound",
"broccoli_.MAX.300 ErrNotFound",
"cabbage__.MAX.520 q6",
"cabbage__.MAX.510 ErrNotFound",
"cabbage__.MAX.500 t1",
"cabbage__.MAX.400 ErrNotFound",
"cabbage__.MAX.300 ErrNotFound",
"celery___.MAX.520 q7",
"celery___.MAX.510 u3",
"celery___.MAX.500 u3",
"celery___.MAX.400 u3",
"celery___.MAX.300 ErrNotFound",
"corn_____.MAX.520 ErrNotFound",
"corn_____.MAX.510 ErrNotFound",
"corn_____.MAX.500 ErrNotFound",
"corn_____.MAX.400 u4",
"corn_____.MAX.300 ErrNotFound",
"d________.MAX.999 ErrNotFound",
"spinach__.MAX.999 u5t2p3q8",
"spinach__.MAX.518 u5t2p3q8",
"spinach__.MAX.517 u5t2p3",
"spinach__.MAX.504 u5t2p3",
"spinach__.MAX.503 u5t2",
"spinach__.MAX.432 u5t2",
"spinach__.MAX.431 u5",
"spinach__.MAX.350 u5",
"spinach__.MAX.349 ErrNotFound",
"a________.SEPARATOR.999 ErrNotFound",
"alfalfa__.SEPARATOR.520 p1",
"alfalfa__.SEPARATOR.510 p1",
"alfalfa__.SEPARATOR.500 r1",
"alfalfa__.SEPARATOR.400 u1",
"alfalfa__.SEPARATOR.300 ErrNotFound",
"asparagus.SEPARATOR.520 q3",
"asparagus.SEPARATOR.510 p2",
"asparagus.SEPARATOR.500 r2",
"asparagus.SEPARATOR.400 ErrNotFound",
"asparagus.SEPARATOR.300 ErrNotFound",
"arugula__.SEPARATOR.520 r3",
"arugula__.SEPARATOR.510 r3",
"arugula__.SEPARATOR.500 r3",
"arugula__.SEPARATOR.400 ErrNotFound",
"arugula__.SEPARATOR.300 ErrNotFound",
"beans____.SEPARATOR.520 q4",
"beans____.SEPARATOR.510 s2",
"beans____.SEPARATOR.500 s2",
"beans____.SEPARATOR.400 ErrNotFound",
"beans____.SEPARATOR.300 ErrNotFound",
"bokchoy__.SEPARATOR.520 ErrNotFound",
"bokchoy__.SEPARATOR.510 ErrNotFound",
"bokchoy__.SEPARATOR.500 ErrNotFound",
"bokchoy__.SEPARATOR.400 u2",
"bokchoy__.SEPARATOR.300 ErrNotFound",
"broccoli_.SEPARATOR.520 q5",
"broccoli_.SEPARATOR.510 s4",
"broccoli_.SEPARATOR.500 s4",
"broccoli_.SEPARATOR.400 ErrNotFound",
"broccoli_.SEPARATOR.300 ErrNotFound",
"cabbage__.SEPARATOR.520 q6",
"cabbage__.SEPARATOR.510 ErrNotFound",
"cabbage__.SEPARATOR.500 t1",
"cabbage__.SEPARATOR.400 ErrNotFound",
"cabbage__.SEPARATOR.300 ErrNotFound",
"celery___.SEPARATOR.520 q7",
"celery___.SEPARATOR.510 u3",
"celery___.SEPARATOR.500 u3",
"celery___.SEPARATOR.400 u3",
"celery___.SEPARATOR.300 ErrNotFound",
"corn_____.SEPARATOR.520 ErrNotFound",
"corn_____.SEPARATOR.510 ErrNotFound",
"corn_____.SEPARATOR.500 ErrNotFound",
"corn_____.SEPARATOR.400 u4",
"corn_____.SEPARATOR.300 ErrNotFound",
"d________.SEPARATOR.999 ErrNotFound",
"spinach__.SEPARATOR.999 u5t2p3q8",
"spinach__.SEPARATOR.518 u5t2p3q8",
"spinach__.SEPARATOR.517 u5t2p3",
"spinach__.SEPARATOR.504 u5t2p3",
"spinach__.SEPARATOR.503 u5t2",
"spinach__.SEPARATOR.432 u5t2",
"spinach__.SEPARATOR.431 u5",
"spinach__.SEPARATOR.350 u5",
"spinach__.SEPARATOR.349 ErrNotFound",
},
},

Expand Down
17 changes: 13 additions & 4 deletions internal/base/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ const (
// InternalKeyKindColumnFamilyBlobIndex = 16
// InternalKeyKindBlobIndex = 17

// InternalKeyKindSeparator is a key used for separator / successor keys
// written to sstable block indexes.
//
// NOTE: the RocksDB value has been repurposed. This was done to ensure that
// keys written to block indexes with value "17" (when 17 happened to be the
// max value, and InternalKeyKindMax was therefore set to 17), remain stable
// when new key kinds are supported in Pebble.
InternalKeyKindSeparator = 17

// This maximum value isn't part of the file format. It's unlikely,
// but future extensions may increase this value.
//
Expand Down Expand Up @@ -72,7 +81,7 @@ var internalKeyKindNames = []string{
InternalKeyKindLogData: "LOGDATA",
InternalKeyKindSingleDelete: "SINGLEDEL",
InternalKeyKindRangeDelete: "RANGEDEL",
InternalKeyKindMax: "MAX",
InternalKeyKindSeparator: "SEPARATOR",
InternalKeyKindInvalid: "INVALID",
}

Expand Down Expand Up @@ -136,7 +145,7 @@ var kindsMap = map[string]InternalKeyKind{
"SET": InternalKeyKindSet,
"MERGE": InternalKeyKindMerge,
"INVALID": InternalKeyKindInvalid,
"MAX": InternalKeyKindMax,
"SEPARATOR": InternalKeyKindSeparator,
}

// ParseInternalKey parses the string representation of an internal key. The
Expand Down Expand Up @@ -224,7 +233,7 @@ func (k InternalKey) Separator(
// any sequence number and kind here to create a valid separator key. We
// use the max sequence number to match the behavior of LevelDB and
// RocksDB.
return MakeInternalKey(buf, InternalKeySeqNumMax, InternalKeyKindMax)
return MakeInternalKey(buf, InternalKeySeqNumMax, InternalKeyKindSeparator)
}
return k
}
Expand All @@ -241,7 +250,7 @@ func (k InternalKey) Successor(cmp Compare, succ Successor, buf []byte) Internal
// any sequence number and kind here to create a valid separator key. We
// use the max sequence number to match the behavior of LevelDB and
// RocksDB.
return MakeInternalKey(buf, InternalKeySeqNumMax, InternalKeyKindMax)
return MakeInternalKey(buf, InternalKeySeqNumMax, InternalKeyKindSeparator)
}
return k
}
Expand Down
Loading

0 comments on commit 305d298

Please sign in to comment.