kvstore.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. // Copyright 2015 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package mvcc
  15. import (
  16. "encoding/binary"
  17. "errors"
  18. "math"
  19. "math/rand"
  20. "sync"
  21. "time"
  22. "github.com/coreos/etcd/lease"
  23. "github.com/coreos/etcd/mvcc/backend"
  24. "github.com/coreos/etcd/mvcc/mvccpb"
  25. "github.com/coreos/etcd/pkg/schedule"
  26. "github.com/coreos/pkg/capnslog"
  27. "golang.org/x/net/context"
  28. )
  29. var (
  30. keyBucketName = []byte("key")
  31. metaBucketName = []byte("meta")
  32. // markedRevBytesLen is the byte length of marked revision.
  33. // The first `revBytesLen` bytes represents a normal revision. The last
  34. // one byte is the mark.
  35. markedRevBytesLen = revBytesLen + 1
  36. markBytePosition = markedRevBytesLen - 1
  37. markTombstone byte = 't'
  38. consistentIndexKeyName = []byte("consistent_index")
  39. scheduledCompactKeyName = []byte("scheduledCompactRev")
  40. finishedCompactKeyName = []byte("finishedCompactRev")
  41. ErrTxnIDMismatch = errors.New("mvcc: txn id mismatch")
  42. ErrCompacted = errors.New("mvcc: required revision has been compacted")
  43. ErrFutureRev = errors.New("mvcc: required revision is a future revision")
  44. ErrCanceled = errors.New("mvcc: watcher is canceled")
  45. plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "mvcc")
  46. )
  47. // ConsistentIndexGetter is an interface that wraps the Get method.
  48. // Consistent index is the offset of an entry in a consistent replicated log.
  49. type ConsistentIndexGetter interface {
  50. // ConsistentIndex returns the consistent index of current executing entry.
  51. ConsistentIndex() uint64
  52. }
  53. type store struct {
  54. mu sync.Mutex // guards the following
  55. ig ConsistentIndexGetter
  56. b backend.Backend
  57. kvindex index
  58. le lease.Lessor
  59. currentRev revision
  60. // the main revision of the last compaction
  61. compactMainRev int64
  62. tx backend.BatchTx
  63. txnID int64 // tracks the current txnID to verify txn operations
  64. txnModify bool
  65. // bytesBuf8 is a byte slice of length 8
  66. // to avoid a repetitive allocation in saveIndex.
  67. bytesBuf8 []byte
  68. changes []mvccpb.KeyValue
  69. fifoSched schedule.Scheduler
  70. stopc chan struct{}
  71. }
  72. // NewStore returns a new store. It is useful to create a store inside
  73. // mvcc pkg. It should only be used for testing externally.
  74. func NewStore(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *store {
  75. s := &store{
  76. b: b,
  77. ig: ig,
  78. kvindex: newTreeIndex(),
  79. le: le,
  80. currentRev: revision{main: 1},
  81. compactMainRev: -1,
  82. bytesBuf8: make([]byte, 8, 8),
  83. fifoSched: schedule.NewFIFOScheduler(),
  84. stopc: make(chan struct{}),
  85. }
  86. if s.le != nil {
  87. s.le.SetRangeDeleter(s)
  88. }
  89. tx := s.b.BatchTx()
  90. tx.Lock()
  91. tx.UnsafeCreateBucket(keyBucketName)
  92. tx.UnsafeCreateBucket(metaBucketName)
  93. tx.Unlock()
  94. s.b.ForceCommit()
  95. if err := s.restore(); err != nil {
  96. // TODO: return the error instead of panic here?
  97. panic("failed to recover store from backend")
  98. }
  99. return s
  100. }
  101. func (s *store) Rev() int64 {
  102. s.mu.Lock()
  103. defer s.mu.Unlock()
  104. return s.currentRev.main
  105. }
  106. func (s *store) FirstRev() int64 {
  107. s.mu.Lock()
  108. defer s.mu.Unlock()
  109. return s.compactMainRev
  110. }
  111. func (s *store) Put(key, value []byte, lease lease.LeaseID) int64 {
  112. id := s.TxnBegin()
  113. s.put(key, value, lease)
  114. s.txnEnd(id)
  115. putCounter.Inc()
  116. return int64(s.currentRev.main)
  117. }
  118. func (s *store) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) {
  119. id := s.TxnBegin()
  120. kvs, count, rev, err := s.rangeKeys(key, end, ro.Limit, ro.Rev, ro.Count)
  121. s.txnEnd(id)
  122. rangeCounter.Inc()
  123. r = &RangeResult{
  124. KVs: kvs,
  125. Count: count,
  126. Rev: rev,
  127. }
  128. return r, err
  129. }
  130. func (s *store) DeleteRange(key, end []byte) (n, rev int64) {
  131. id := s.TxnBegin()
  132. n = s.deleteRange(key, end)
  133. s.txnEnd(id)
  134. deleteCounter.Inc()
  135. return n, int64(s.currentRev.main)
  136. }
  137. func (s *store) TxnBegin() int64 {
  138. s.mu.Lock()
  139. s.currentRev.sub = 0
  140. s.tx = s.b.BatchTx()
  141. s.tx.Lock()
  142. s.txnID = rand.Int63()
  143. return s.txnID
  144. }
  145. func (s *store) TxnEnd(txnID int64) error {
  146. err := s.txnEnd(txnID)
  147. if err != nil {
  148. return err
  149. }
  150. txnCounter.Inc()
  151. return nil
  152. }
  153. // txnEnd is used for unlocking an internal txn. It does
  154. // not increase the txnCounter.
  155. func (s *store) txnEnd(txnID int64) error {
  156. if txnID != s.txnID {
  157. return ErrTxnIDMismatch
  158. }
  159. // only update index if the txn modifies the mvcc state.
  160. // read only txn might execute with one write txn concurrently,
  161. // it should not write its index to mvcc.
  162. if s.txnModify {
  163. s.saveIndex()
  164. }
  165. s.txnModify = false
  166. s.tx.Unlock()
  167. if s.currentRev.sub != 0 {
  168. s.currentRev.main += 1
  169. }
  170. s.currentRev.sub = 0
  171. s.mu.Unlock()
  172. return nil
  173. }
  174. func (s *store) TxnRange(txnID int64, key, end []byte, ro RangeOptions) (r *RangeResult, err error) {
  175. if txnID != s.txnID {
  176. return nil, ErrTxnIDMismatch
  177. }
  178. kvs, count, rev, err := s.rangeKeys(key, end, ro.Limit, ro.Rev, ro.Count)
  179. r = &RangeResult{
  180. KVs: kvs,
  181. Count: count,
  182. Rev: rev,
  183. }
  184. return r, err
  185. }
  186. func (s *store) TxnPut(txnID int64, key, value []byte, lease lease.LeaseID) (rev int64, err error) {
  187. if txnID != s.txnID {
  188. return 0, ErrTxnIDMismatch
  189. }
  190. s.put(key, value, lease)
  191. return int64(s.currentRev.main + 1), nil
  192. }
  193. func (s *store) TxnDeleteRange(txnID int64, key, end []byte) (n, rev int64, err error) {
  194. if txnID != s.txnID {
  195. return 0, 0, ErrTxnIDMismatch
  196. }
  197. n = s.deleteRange(key, end)
  198. if n != 0 || s.currentRev.sub != 0 {
  199. rev = int64(s.currentRev.main + 1)
  200. } else {
  201. rev = int64(s.currentRev.main)
  202. }
  203. return n, rev, nil
  204. }
  205. func (s *store) compactBarrier(ctx context.Context, ch chan struct{}) {
  206. if ctx == nil || ctx.Err() != nil {
  207. s.mu.Lock()
  208. select {
  209. case <-s.stopc:
  210. default:
  211. f := func(ctx context.Context) { s.compactBarrier(ctx, ch) }
  212. s.fifoSched.Schedule(f)
  213. }
  214. s.mu.Unlock()
  215. return
  216. }
  217. close(ch)
  218. }
  219. func (s *store) Compact(rev int64) (<-chan struct{}, error) {
  220. s.mu.Lock()
  221. defer s.mu.Unlock()
  222. if rev <= s.compactMainRev {
  223. ch := make(chan struct{})
  224. f := func(ctx context.Context) { s.compactBarrier(ctx, ch) }
  225. s.fifoSched.Schedule(f)
  226. return ch, ErrCompacted
  227. }
  228. if rev > s.currentRev.main {
  229. return nil, ErrFutureRev
  230. }
  231. start := time.Now()
  232. s.compactMainRev = rev
  233. rbytes := newRevBytes()
  234. revToBytes(revision{main: rev}, rbytes)
  235. tx := s.b.BatchTx()
  236. tx.Lock()
  237. tx.UnsafePut(metaBucketName, scheduledCompactKeyName, rbytes)
  238. tx.Unlock()
  239. // ensure that desired compaction is persisted
  240. s.b.ForceCommit()
  241. keep := s.kvindex.Compact(rev)
  242. ch := make(chan struct{})
  243. var j = func(ctx context.Context) {
  244. if ctx.Err() != nil {
  245. s.compactBarrier(ctx, ch)
  246. return
  247. }
  248. if !s.scheduleCompaction(rev, keep) {
  249. s.compactBarrier(nil, ch)
  250. return
  251. }
  252. close(ch)
  253. }
  254. s.fifoSched.Schedule(j)
  255. indexCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond))
  256. return ch, nil
  257. }
  258. // DefaultIgnores is a map of keys to ignore in hash checking.
  259. var DefaultIgnores map[backend.IgnoreKey]struct{}
  260. func init() {
  261. DefaultIgnores = map[backend.IgnoreKey]struct{}{
  262. // consistent index might be changed due to v2 internal sync, which
  263. // is not controllable by the user.
  264. {Bucket: string(metaBucketName), Key: string(consistentIndexKeyName)}: {},
  265. }
  266. }
  267. func (s *store) Hash() (uint32, int64, error) {
  268. s.mu.Lock()
  269. defer s.mu.Unlock()
  270. start := time.Now()
  271. s.b.ForceCommit()
  272. h, err := s.b.Hash(DefaultIgnores)
  273. hashDurations.Observe(time.Since(start).Seconds())
  274. rev := s.currentRev.main
  275. return h, rev, err
  276. }
  277. func (s *store) Commit() {
  278. s.mu.Lock()
  279. defer s.mu.Unlock()
  280. s.tx = s.b.BatchTx()
  281. s.tx.Lock()
  282. s.saveIndex()
  283. s.tx.Unlock()
  284. s.b.ForceCommit()
  285. }
  286. func (s *store) Restore(b backend.Backend) error {
  287. s.mu.Lock()
  288. defer s.mu.Unlock()
  289. close(s.stopc)
  290. s.fifoSched.Stop()
  291. s.b = b
  292. s.kvindex = newTreeIndex()
  293. s.currentRev = revision{main: 1}
  294. s.compactMainRev = -1
  295. s.tx = b.BatchTx()
  296. s.txnID = -1
  297. s.fifoSched = schedule.NewFIFOScheduler()
  298. s.stopc = make(chan struct{})
  299. return s.restore()
  300. }
  301. func (s *store) restore() error {
  302. reportDbTotalSizeInBytesMu.Lock()
  303. reportDbTotalSizeInBytes = func() float64 { return float64(s.b.Size()) }
  304. reportDbTotalSizeInBytesMu.Unlock()
  305. reportDbTotalSizeInUseInBytesMu.Lock()
  306. reportDbTotalSizeInUseInBytes = func() float64 { return float64(s.b.SizeInUse()) }
  307. reportDbTotalSizeInUseInBytesMu.Unlock()
  308. min, max := newRevBytes(), newRevBytes()
  309. revToBytes(revision{main: 1}, min)
  310. revToBytes(revision{main: math.MaxInt64, sub: math.MaxInt64}, max)
  311. keyToLease := make(map[string]lease.LeaseID)
  312. // use an unordered map to hold the temp index data to speed up
  313. // the initial key index recovery.
  314. // we will convert this unordered map into the tree index later.
  315. unordered := make(map[string]*keyIndex, 100000)
  316. // restore index
  317. tx := s.b.BatchTx()
  318. tx.Lock()
  319. _, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0)
  320. if len(finishedCompactBytes) != 0 {
  321. s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
  322. plog.Printf("restore compact to %d", s.compactMainRev)
  323. }
  324. // TODO: limit N to reduce max memory usage
  325. keys, vals := tx.UnsafeRange(keyBucketName, min, max, 0)
  326. for i, key := range keys {
  327. var kv mvccpb.KeyValue
  328. if err := kv.Unmarshal(vals[i]); err != nil {
  329. plog.Fatalf("cannot unmarshal event: %v", err)
  330. }
  331. rev := bytesToRev(key[:revBytesLen])
  332. // restore index
  333. switch {
  334. case isTombstone(key):
  335. if ki, ok := unordered[string(kv.Key)]; ok {
  336. ki.tombstone(rev.main, rev.sub)
  337. }
  338. delete(keyToLease, string(kv.Key))
  339. default:
  340. ki, ok := unordered[string(kv.Key)]
  341. if ok {
  342. ki.put(rev.main, rev.sub)
  343. } else {
  344. ki = &keyIndex{key: kv.Key}
  345. ki.restore(revision{kv.CreateRevision, 0}, rev, kv.Version)
  346. unordered[string(kv.Key)] = ki
  347. }
  348. if lid := lease.LeaseID(kv.Lease); lid != lease.NoLease {
  349. keyToLease[string(kv.Key)] = lid
  350. } else {
  351. delete(keyToLease, string(kv.Key))
  352. }
  353. }
  354. // update revision
  355. s.currentRev = rev
  356. }
  357. // restore the tree index from the unordered index.
  358. for _, v := range unordered {
  359. s.kvindex.Insert(v)
  360. }
  361. // keys in the range [compacted revision -N, compaction] might all be deleted due to compaction.
  362. // the correct revision should be set to compaction revision in the case, not the largest revision
  363. // we have seen.
  364. if s.currentRev.main < s.compactMainRev {
  365. s.currentRev.main = s.compactMainRev
  366. }
  367. for key, lid := range keyToLease {
  368. if s.le == nil {
  369. panic("no lessor to attach lease")
  370. }
  371. err := s.le.Attach(lid, []lease.LeaseItem{{Key: key}})
  372. if err != nil {
  373. plog.Errorf("unexpected Attach error: %v", err)
  374. }
  375. }
  376. _, scheduledCompactBytes := tx.UnsafeRange(metaBucketName, scheduledCompactKeyName, nil, 0)
  377. scheduledCompact := int64(0)
  378. if len(scheduledCompactBytes) != 0 {
  379. scheduledCompact = bytesToRev(scheduledCompactBytes[0]).main
  380. if scheduledCompact <= s.compactMainRev {
  381. scheduledCompact = 0
  382. }
  383. }
  384. tx.Unlock()
  385. if scheduledCompact != 0 {
  386. s.Compact(scheduledCompact)
  387. plog.Printf("resume scheduled compaction at %d", scheduledCompact)
  388. }
  389. return nil
  390. }
  391. func (s *store) Close() error {
  392. close(s.stopc)
  393. s.fifoSched.Stop()
  394. return nil
  395. }
  396. func (a *store) Equal(b *store) bool {
  397. if a.currentRev != b.currentRev {
  398. return false
  399. }
  400. if a.compactMainRev != b.compactMainRev {
  401. return false
  402. }
  403. return a.kvindex.Equal(b.kvindex)
  404. }
  405. // range is a keyword in Go, add Keys suffix.
  406. func (s *store) rangeKeys(key, end []byte, limit, rangeRev int64, countOnly bool) (kvs []mvccpb.KeyValue, count int, curRev int64, err error) {
  407. curRev = int64(s.currentRev.main)
  408. if s.currentRev.sub > 0 {
  409. curRev += 1
  410. }
  411. if rangeRev > curRev {
  412. return nil, -1, s.currentRev.main, ErrFutureRev
  413. }
  414. var rev int64
  415. if rangeRev <= 0 {
  416. rev = curRev
  417. } else {
  418. rev = rangeRev
  419. }
  420. if rev < s.compactMainRev {
  421. return nil, -1, 0, ErrCompacted
  422. }
  423. _, revpairs := s.kvindex.Range(key, end, int64(rev))
  424. if len(revpairs) == 0 {
  425. return nil, 0, curRev, nil
  426. }
  427. if countOnly {
  428. return nil, len(revpairs), curRev, nil
  429. }
  430. for _, revpair := range revpairs {
  431. start, end := revBytesRange(revpair)
  432. _, vs := s.tx.UnsafeRange(keyBucketName, start, end, 0)
  433. if len(vs) != 1 {
  434. plog.Fatalf("range cannot find rev (%d,%d)", revpair.main, revpair.sub)
  435. }
  436. var kv mvccpb.KeyValue
  437. if err := kv.Unmarshal(vs[0]); err != nil {
  438. plog.Fatalf("cannot unmarshal event: %v", err)
  439. }
  440. kvs = append(kvs, kv)
  441. if limit > 0 && len(kvs) >= int(limit) {
  442. break
  443. }
  444. }
  445. return kvs, len(revpairs), curRev, nil
  446. }
  447. func (s *store) put(key, value []byte, leaseID lease.LeaseID) {
  448. s.txnModify = true
  449. rev := s.currentRev.main + 1
  450. c := rev
  451. oldLease := lease.NoLease
  452. // if the key exists before, use its previous created and
  453. // get its previous leaseID
  454. _, created, ver, err := s.kvindex.Get(key, rev)
  455. if err == nil {
  456. c = created.main
  457. oldLease = s.le.GetLease(lease.LeaseItem{Key: string(key)})
  458. }
  459. ibytes := newRevBytes()
  460. revToBytes(revision{main: rev, sub: s.currentRev.sub}, ibytes)
  461. ver = ver + 1
  462. kv := mvccpb.KeyValue{
  463. Key: key,
  464. Value: value,
  465. CreateRevision: c,
  466. ModRevision: rev,
  467. Version: ver,
  468. Lease: int64(leaseID),
  469. }
  470. d, err := kv.Marshal()
  471. if err != nil {
  472. plog.Fatalf("cannot marshal event: %v", err)
  473. }
  474. s.tx.UnsafeSeqPut(keyBucketName, ibytes, d)
  475. s.kvindex.Put(key, revision{main: rev, sub: s.currentRev.sub})
  476. s.changes = append(s.changes, kv)
  477. s.currentRev.sub += 1
  478. if oldLease != lease.NoLease {
  479. if s.le == nil {
  480. panic("no lessor to detach lease")
  481. }
  482. err = s.le.Detach(oldLease, []lease.LeaseItem{{Key: string(key)}})
  483. if err != nil {
  484. plog.Errorf("unexpected error from lease detach: %v", err)
  485. }
  486. }
  487. if leaseID != lease.NoLease {
  488. if s.le == nil {
  489. panic("no lessor to attach lease")
  490. }
  491. err = s.le.Attach(leaseID, []lease.LeaseItem{{Key: string(key)}})
  492. if err != nil {
  493. panic("unexpected error from lease Attach")
  494. }
  495. }
  496. }
  497. func (s *store) deleteRange(key, end []byte) int64 {
  498. s.txnModify = true
  499. rrev := s.currentRev.main
  500. if s.currentRev.sub > 0 {
  501. rrev += 1
  502. }
  503. keys, revs := s.kvindex.Range(key, end, rrev)
  504. if len(keys) == 0 {
  505. return 0
  506. }
  507. for i, key := range keys {
  508. s.delete(key, revs[i])
  509. }
  510. return int64(len(keys))
  511. }
  512. func (s *store) delete(key []byte, rev revision) {
  513. mainrev := s.currentRev.main + 1
  514. ibytes := newRevBytes()
  515. revToBytes(revision{main: mainrev, sub: s.currentRev.sub}, ibytes)
  516. ibytes = appendMarkTombstone(ibytes)
  517. kv := mvccpb.KeyValue{
  518. Key: key,
  519. }
  520. d, err := kv.Marshal()
  521. if err != nil {
  522. plog.Fatalf("cannot marshal event: %v", err)
  523. }
  524. s.tx.UnsafeSeqPut(keyBucketName, ibytes, d)
  525. err = s.kvindex.Tombstone(key, revision{main: mainrev, sub: s.currentRev.sub})
  526. if err != nil {
  527. plog.Fatalf("cannot tombstone an existing key (%s): %v", string(key), err)
  528. }
  529. s.changes = append(s.changes, kv)
  530. s.currentRev.sub += 1
  531. item := lease.LeaseItem{Key: string(key)}
  532. leaseID := s.le.GetLease(item)
  533. if leaseID != lease.NoLease {
  534. err = s.le.Detach(leaseID, []lease.LeaseItem{item})
  535. if err != nil {
  536. plog.Errorf("cannot detach %v", err)
  537. }
  538. }
  539. }
  540. func (s *store) getChanges() []mvccpb.KeyValue {
  541. changes := s.changes
  542. s.changes = make([]mvccpb.KeyValue, 0, 4)
  543. return changes
  544. }
  545. func (s *store) saveIndex() {
  546. if s.ig == nil {
  547. return
  548. }
  549. tx := s.tx
  550. bs := s.bytesBuf8
  551. binary.BigEndian.PutUint64(bs, s.ig.ConsistentIndex())
  552. // put the index into the underlying backend
  553. // tx has been locked in TxnBegin, so there is no need to lock it again
  554. tx.UnsafePut(metaBucketName, consistentIndexKeyName, bs)
  555. }
  556. func (s *store) ConsistentIndex() uint64 {
  557. // TODO: cache index in a uint64 field?
  558. tx := s.b.BatchTx()
  559. tx.Lock()
  560. defer tx.Unlock()
  561. _, vs := tx.UnsafeRange(metaBucketName, consistentIndexKeyName, nil, 0)
  562. if len(vs) == 0 {
  563. return 0
  564. }
  565. return binary.BigEndian.Uint64(vs[0])
  566. }
  567. // appendMarkTombstone appends tombstone mark to normal revision bytes.
  568. func appendMarkTombstone(b []byte) []byte {
  569. if len(b) != revBytesLen {
  570. plog.Panicf("cannot append mark to non normal revision bytes")
  571. }
  572. return append(b, markTombstone)
  573. }
  574. // isTombstone checks whether the revision bytes is a tombstone.
  575. func isTombstone(b []byte) bool {
  576. return len(b) == markedRevBytesLen && b[markBytePosition] == markTombstone
  577. }
  578. // revBytesRange returns the range of revision bytes at
  579. // the given revision.
  580. func revBytesRange(rev revision) (start, end []byte) {
  581. start = newRevBytes()
  582. revToBytes(rev, start)
  583. end = newRevBytes()
  584. endRev := revision{main: rev.main, sub: rev.sub + 1}
  585. revToBytes(endRev, end)
  586. return start, end
  587. }