*** * verifyKeyOrder checks whether an entry with given #index on pgId (pageType: "branch|leaf") that has given "key", * is within range determined by (previousKey..maxKeyOpen) and reports found violations to the channel (ch). */
(pgId common.Pgid, pageType string, index int, key []byte, previousKey []byte, maxKeyOpen []byte, ch chan error, keyToString func([]byte) string, pagesStack []common.Pgid)
| 230 | * is within range determined by (previousKey..maxKeyOpen) and reports found violations to the channel (ch). |
| 231 | */ |
| 232 | func verifyKeyOrder(pgId common.Pgid, pageType string, index int, key []byte, previousKey []byte, maxKeyOpen []byte, ch chan error, keyToString func([]byte) string, pagesStack []common.Pgid) { |
| 233 | if index == 0 && previousKey != nil && compareKeys(previousKey, key) > 0 { |
| 234 | ch <- fmt.Errorf("the first key[%d]=(hex)%s on %s page(%d) needs to be >= the key in the ancestor (%s). Stack: %v", |
| 235 | index, keyToString(key), pageType, pgId, keyToString(previousKey), pagesStack) |
| 236 | } |
| 237 | if index > 0 { |
| 238 | cmpRet := compareKeys(previousKey, key) |
| 239 | if cmpRet > 0 { |
| 240 | ch <- fmt.Errorf("key[%d]=(hex)%s on %s page(%d) needs to be > (found <) than previous element (hex)%s. Stack: %v", |
| 241 | index, keyToString(key), pageType, pgId, keyToString(previousKey), pagesStack) |
| 242 | } |
| 243 | if cmpRet == 0 { |
| 244 | ch <- fmt.Errorf("key[%d]=(hex)%s on %s page(%d) needs to be > (found =) than previous element (hex)%s. Stack: %v", |
| 245 | index, keyToString(key), pageType, pgId, keyToString(previousKey), pagesStack) |
| 246 | } |
| 247 | } |
| 248 | if maxKeyOpen != nil && compareKeys(key, maxKeyOpen) >= 0 { |
| 249 | ch <- fmt.Errorf("key[%d]=(hex)%s on %s page(%d) needs to be < than key of the next element in ancestor (hex)%s. Pages stack: %v", |
| 250 | index, keyToString(key), pageType, pgId, keyToString(previousKey), pagesStack) |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // =========================================================================================== |
| 255 |
no test coverage detected