fix the partiton for keycomparator (#35)
This commit is contained in:
Родитель
7b94f657a3
Коммит
54726b44e7
|
@ -153,7 +153,7 @@ func (t *ResourceEventCountsTable) GetUniquePartitionList(txn badgerwrap.Txn) ([
|
|||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *ResourceEventCountsTable) GetPreviousKey(txn badgerwrap.Txn, key *EventCountKey, keyPrefix *EventCountKey) (*EventCountKey, error) {
|
||||
func (t *ResourceEventCountsTable) GetPreviousKey(txn badgerwrap.Txn, key *EventCountKey, keyComparator *EventCountKey) (*EventCountKey, error) {
|
||||
partitionList, err := t.GetUniquePartitionList(txn)
|
||||
if err != nil {
|
||||
return &EventCountKey{}, errors.Wrapf(err, "failed to get partition list from table:%v", t.tableName)
|
||||
|
@ -164,7 +164,7 @@ func (t *ResourceEventCountsTable) GetPreviousKey(txn badgerwrap.Txn, key *Event
|
|||
if prePart > currentPartition {
|
||||
continue
|
||||
} else {
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyPrefix)
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyComparator)
|
||||
if err != nil {
|
||||
return &EventCountKey{}, errors.Wrapf(err, "Failure getting previous key for %v, for partition id:%v", key.String(), prePart)
|
||||
}
|
||||
|
@ -173,11 +173,11 @@ func (t *ResourceEventCountsTable) GetPreviousKey(txn badgerwrap.Txn, key *Event
|
|||
}
|
||||
}
|
||||
}
|
||||
return &EventCountKey{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyPrefix:%v", t.tableName, key.String(), keyPrefix)
|
||||
return &EventCountKey{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyComparator:%v", t.tableName, key.String(), keyComparator)
|
||||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *ResourceEventCountsTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *EventCountKey, keyPrefix *EventCountKey) (bool, *EventCountKey, error) {
|
||||
func (t *ResourceEventCountsTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *EventCountKey, keyComparator *EventCountKey) (bool, *EventCountKey, error) {
|
||||
iterOpt := badger.DefaultIteratorOptions
|
||||
iterOpt.Reverse = true
|
||||
itr := txn.NewIterator(iterOpt)
|
||||
|
@ -187,8 +187,9 @@ func (t *ResourceEventCountsTable) getLastMatchingKeyInPartition(txn badgerwrap.
|
|||
|
||||
// update partition with current value
|
||||
curKey.SetPartitionId(curPartition)
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
keyComparator.SetPartitionId(curPartition)
|
||||
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
itr.Seek([]byte(keySeekStr))
|
||||
|
||||
// if the result is same as key, we want to check its previous one
|
||||
|
@ -196,7 +197,7 @@ func (t *ResourceEventCountsTable) getLastMatchingKeyInPartition(txn badgerwrap.
|
|||
itr.Next()
|
||||
}
|
||||
|
||||
if itr.ValidForPrefix([]byte(keyPrefix.String())) {
|
||||
if itr.ValidForPrefix([]byte(keyComparator.String())) {
|
||||
key := &EventCountKey{}
|
||||
err := key.Parse(string(itr.Item().Key()))
|
||||
if err != nil {
|
||||
|
|
|
@ -153,7 +153,7 @@ func (t *ResourceSummaryTable) GetUniquePartitionList(txn badgerwrap.Txn) ([]str
|
|||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *ResourceSummaryTable) GetPreviousKey(txn badgerwrap.Txn, key *ResourceSummaryKey, keyPrefix *ResourceSummaryKey) (*ResourceSummaryKey, error) {
|
||||
func (t *ResourceSummaryTable) GetPreviousKey(txn badgerwrap.Txn, key *ResourceSummaryKey, keyComparator *ResourceSummaryKey) (*ResourceSummaryKey, error) {
|
||||
partitionList, err := t.GetUniquePartitionList(txn)
|
||||
if err != nil {
|
||||
return &ResourceSummaryKey{}, errors.Wrapf(err, "failed to get partition list from table:%v", t.tableName)
|
||||
|
@ -164,7 +164,7 @@ func (t *ResourceSummaryTable) GetPreviousKey(txn badgerwrap.Txn, key *ResourceS
|
|||
if prePart > currentPartition {
|
||||
continue
|
||||
} else {
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyPrefix)
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyComparator)
|
||||
if err != nil {
|
||||
return &ResourceSummaryKey{}, errors.Wrapf(err, "Failure getting previous key for %v, for partition id:%v", key.String(), prePart)
|
||||
}
|
||||
|
@ -173,11 +173,11 @@ func (t *ResourceSummaryTable) GetPreviousKey(txn badgerwrap.Txn, key *ResourceS
|
|||
}
|
||||
}
|
||||
}
|
||||
return &ResourceSummaryKey{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyPrefix:%v", t.tableName, key.String(), keyPrefix)
|
||||
return &ResourceSummaryKey{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyComparator:%v", t.tableName, key.String(), keyComparator)
|
||||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *ResourceSummaryTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *ResourceSummaryKey, keyPrefix *ResourceSummaryKey) (bool, *ResourceSummaryKey, error) {
|
||||
func (t *ResourceSummaryTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *ResourceSummaryKey, keyComparator *ResourceSummaryKey) (bool, *ResourceSummaryKey, error) {
|
||||
iterOpt := badger.DefaultIteratorOptions
|
||||
iterOpt.Reverse = true
|
||||
itr := txn.NewIterator(iterOpt)
|
||||
|
@ -187,8 +187,9 @@ func (t *ResourceSummaryTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn,
|
|||
|
||||
// update partition with current value
|
||||
curKey.SetPartitionId(curPartition)
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
keyComparator.SetPartitionId(curPartition)
|
||||
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
itr.Seek([]byte(keySeekStr))
|
||||
|
||||
// if the result is same as key, we want to check its previous one
|
||||
|
@ -196,7 +197,7 @@ func (t *ResourceSummaryTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn,
|
|||
itr.Next()
|
||||
}
|
||||
|
||||
if itr.ValidForPrefix([]byte(keyPrefix.String())) {
|
||||
if itr.ValidForPrefix([]byte(keyComparator.String())) {
|
||||
key := &ResourceSummaryKey{}
|
||||
err := key.Parse(string(itr.Item().Key()))
|
||||
if err != nil {
|
||||
|
|
|
@ -153,7 +153,7 @@ func (t *ValueTypeTable) GetUniquePartitionList(txn badgerwrap.Txn) ([]string, e
|
|||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *ValueTypeTable) GetPreviousKey(txn badgerwrap.Txn, key *KeyType, keyPrefix *KeyType) (*KeyType, error) {
|
||||
func (t *ValueTypeTable) GetPreviousKey(txn badgerwrap.Txn, key *KeyType, keyComparator *KeyType) (*KeyType, error) {
|
||||
partitionList, err := t.GetUniquePartitionList(txn)
|
||||
if err != nil {
|
||||
return &KeyType{}, errors.Wrapf(err, "failed to get partition list from table:%v", t.tableName)
|
||||
|
@ -164,7 +164,7 @@ func (t *ValueTypeTable) GetPreviousKey(txn badgerwrap.Txn, key *KeyType, keyPre
|
|||
if prePart > currentPartition {
|
||||
continue
|
||||
} else {
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyPrefix)
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyComparator)
|
||||
if err != nil {
|
||||
return &KeyType{}, errors.Wrapf(err, "Failure getting previous key for %v, for partition id:%v", key.String(), prePart)
|
||||
}
|
||||
|
@ -173,11 +173,11 @@ func (t *ValueTypeTable) GetPreviousKey(txn badgerwrap.Txn, key *KeyType, keyPre
|
|||
}
|
||||
}
|
||||
}
|
||||
return &KeyType{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyPrefix:%v", t.tableName, key.String(), keyPrefix)
|
||||
return &KeyType{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyComparator:%v", t.tableName, key.String(), keyComparator)
|
||||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *ValueTypeTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *KeyType, keyPrefix *KeyType) (bool, *KeyType, error) {
|
||||
func (t *ValueTypeTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *KeyType, keyComparator *KeyType) (bool, *KeyType, error) {
|
||||
iterOpt := badger.DefaultIteratorOptions
|
||||
iterOpt.Reverse = true
|
||||
itr := txn.NewIterator(iterOpt)
|
||||
|
@ -187,8 +187,9 @@ func (t *ValueTypeTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPa
|
|||
|
||||
// update partition with current value
|
||||
curKey.SetPartitionId(curPartition)
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
keyComparator.SetPartitionId(curPartition)
|
||||
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
itr.Seek([]byte(keySeekStr))
|
||||
|
||||
// if the result is same as key, we want to check its previous one
|
||||
|
@ -196,7 +197,7 @@ func (t *ValueTypeTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPa
|
|||
itr.Next()
|
||||
}
|
||||
|
||||
if itr.ValidForPrefix([]byte(keyPrefix.String())) {
|
||||
if itr.ValidForPrefix([]byte(keyComparator.String())) {
|
||||
key := &KeyType{}
|
||||
err := key.Parse(string(itr.Item().Key()))
|
||||
if err != nil {
|
||||
|
|
|
@ -153,7 +153,7 @@ func (t *WatchActivityTable) GetUniquePartitionList(txn badgerwrap.Txn) ([]strin
|
|||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *WatchActivityTable) GetPreviousKey(txn badgerwrap.Txn, key *WatchActivityKey, keyPrefix *WatchActivityKey) (*WatchActivityKey, error) {
|
||||
func (t *WatchActivityTable) GetPreviousKey(txn badgerwrap.Txn, key *WatchActivityKey, keyComparator *WatchActivityKey) (*WatchActivityKey, error) {
|
||||
partitionList, err := t.GetUniquePartitionList(txn)
|
||||
if err != nil {
|
||||
return &WatchActivityKey{}, errors.Wrapf(err, "failed to get partition list from table:%v", t.tableName)
|
||||
|
@ -164,7 +164,7 @@ func (t *WatchActivityTable) GetPreviousKey(txn badgerwrap.Txn, key *WatchActivi
|
|||
if prePart > currentPartition {
|
||||
continue
|
||||
} else {
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyPrefix)
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyComparator)
|
||||
if err != nil {
|
||||
return &WatchActivityKey{}, errors.Wrapf(err, "Failure getting previous key for %v, for partition id:%v", key.String(), prePart)
|
||||
}
|
||||
|
@ -173,11 +173,11 @@ func (t *WatchActivityTable) GetPreviousKey(txn badgerwrap.Txn, key *WatchActivi
|
|||
}
|
||||
}
|
||||
}
|
||||
return &WatchActivityKey{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyPrefix:%v", t.tableName, key.String(), keyPrefix)
|
||||
return &WatchActivityKey{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyComparator:%v", t.tableName, key.String(), keyComparator)
|
||||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *WatchActivityTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *WatchActivityKey, keyPrefix *WatchActivityKey) (bool, *WatchActivityKey, error) {
|
||||
func (t *WatchActivityTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *WatchActivityKey, keyComparator *WatchActivityKey) (bool, *WatchActivityKey, error) {
|
||||
iterOpt := badger.DefaultIteratorOptions
|
||||
iterOpt.Reverse = true
|
||||
itr := txn.NewIterator(iterOpt)
|
||||
|
@ -187,8 +187,9 @@ func (t *WatchActivityTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, c
|
|||
|
||||
// update partition with current value
|
||||
curKey.SetPartitionId(curPartition)
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
keyComparator.SetPartitionId(curPartition)
|
||||
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
itr.Seek([]byte(keySeekStr))
|
||||
|
||||
// if the result is same as key, we want to check its previous one
|
||||
|
@ -196,7 +197,7 @@ func (t *WatchActivityTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, c
|
|||
itr.Next()
|
||||
}
|
||||
|
||||
if itr.ValidForPrefix([]byte(keyPrefix.String())) {
|
||||
if itr.ValidForPrefix([]byte(keyComparator.String())) {
|
||||
key := &WatchActivityKey{}
|
||||
err := key.Parse(string(itr.Item().Key()))
|
||||
if err != nil {
|
||||
|
|
|
@ -153,7 +153,7 @@ func (t *KubeWatchResultTable) GetUniquePartitionList(txn badgerwrap.Txn) ([]str
|
|||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *KubeWatchResultTable) GetPreviousKey(txn badgerwrap.Txn, key *WatchTableKey, keyPrefix *WatchTableKey) (*WatchTableKey, error) {
|
||||
func (t *KubeWatchResultTable) GetPreviousKey(txn badgerwrap.Txn, key *WatchTableKey, keyComparator *WatchTableKey) (*WatchTableKey, error) {
|
||||
partitionList, err := t.GetUniquePartitionList(txn)
|
||||
if err != nil {
|
||||
return &WatchTableKey{}, errors.Wrapf(err, "failed to get partition list from table:%v", t.tableName)
|
||||
|
@ -164,7 +164,7 @@ func (t *KubeWatchResultTable) GetPreviousKey(txn badgerwrap.Txn, key *WatchTabl
|
|||
if prePart > currentPartition {
|
||||
continue
|
||||
} else {
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyPrefix)
|
||||
prevFound, prevKey, err := t.getLastMatchingKeyInPartition(txn, prePart, key, keyComparator)
|
||||
if err != nil {
|
||||
return &WatchTableKey{}, errors.Wrapf(err, "Failure getting previous key for %v, for partition id:%v", key.String(), prePart)
|
||||
}
|
||||
|
@ -173,11 +173,11 @@ func (t *KubeWatchResultTable) GetPreviousKey(txn badgerwrap.Txn, key *WatchTabl
|
|||
}
|
||||
}
|
||||
}
|
||||
return &WatchTableKey{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyPrefix:%v", t.tableName, key.String(), keyPrefix)
|
||||
return &WatchTableKey{}, fmt.Errorf("failed to get any previous key in table:%v, for key:%v, keyComparator:%v", t.tableName, key.String(), keyComparator)
|
||||
}
|
||||
|
||||
//todo: need to add unit test
|
||||
func (t *KubeWatchResultTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *WatchTableKey, keyPrefix *WatchTableKey) (bool, *WatchTableKey, error) {
|
||||
func (t *KubeWatchResultTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn, curPartition string, curKey *WatchTableKey, keyComparator *WatchTableKey) (bool, *WatchTableKey, error) {
|
||||
iterOpt := badger.DefaultIteratorOptions
|
||||
iterOpt.Reverse = true
|
||||
itr := txn.NewIterator(iterOpt)
|
||||
|
@ -187,8 +187,9 @@ func (t *KubeWatchResultTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn,
|
|||
|
||||
// update partition with current value
|
||||
curKey.SetPartitionId(curPartition)
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
keyComparator.SetPartitionId(curPartition)
|
||||
|
||||
keySeekStr := curKey.String() + string(rune(255))
|
||||
itr.Seek([]byte(keySeekStr))
|
||||
|
||||
// if the result is same as key, we want to check its previous one
|
||||
|
@ -196,7 +197,7 @@ func (t *KubeWatchResultTable) getLastMatchingKeyInPartition(txn badgerwrap.Txn,
|
|||
itr.Next()
|
||||
}
|
||||
|
||||
if itr.ValidForPrefix([]byte(keyPrefix.String())) {
|
||||
if itr.ValidForPrefix([]byte(keyComparator.String())) {
|
||||
key := &WatchTableKey{}
|
||||
err := key.Parse(string(itr.Item().Key()))
|
||||
if err != nil {
|
||||
|
|
Загрузка…
Ссылка в новой задаче