mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Rename seq to bucket2seq.
This commit is contained in:
parent
4a2ffc2cbe
commit
eebe67d87d
@ -511,7 +511,7 @@ func defragdb(odb, tmpdb *bolt.DB, limit int) error {
|
|||||||
if berr != nil {
|
if berr != nil {
|
||||||
return berr
|
return berr
|
||||||
}
|
}
|
||||||
tmpb.FillPercent = 0.9 // for seq write in for each
|
tmpb.FillPercent = 0.9 // for bucket2seq write in for each
|
||||||
|
|
||||||
if err = b.ForEach(func(k, v []byte) error {
|
if err = b.ForEach(func(k, v []byte) error {
|
||||||
count++
|
count++
|
||||||
@ -525,7 +525,7 @@ func defragdb(odb, tmpdb *bolt.DB, limit int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tmpb = tmptx.Bucket(next)
|
tmpb = tmptx.Bucket(next)
|
||||||
tmpb.FillPercent = 0.9 // for seq write in for each
|
tmpb.FillPercent = 0.9 // for bucket2seq write in for each
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ func newBatchTxBuffered(backend *backend) *batchTxBuffered {
|
|||||||
batchTx: batchTx{backend: backend},
|
batchTx: batchTx{backend: backend},
|
||||||
buf: txWriteBuffer{
|
buf: txWriteBuffer{
|
||||||
txBuffer: txBuffer{make(map[string]*bucketBuffer)},
|
txBuffer: txBuffer{make(map[string]*bucketBuffer)},
|
||||||
seq: make(map[string]bool),
|
bucket2seq: make(map[string]bool),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
@ -39,31 +39,38 @@ type txWriteBuffer struct {
|
|||||||
txBuffer
|
txBuffer
|
||||||
// Map from bucket name into information whether this bucket is edited
|
// Map from bucket name into information whether this bucket is edited
|
||||||
// sequentially (i.e. keys are growing monotonically).
|
// sequentially (i.e. keys are growing monotonically).
|
||||||
seq map[string]bool
|
bucket2seq map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Passing bucket as an (int) enum would avoid a lot of byte[]->string->hash conversions.
|
||||||
func (txw *txWriteBuffer) put(bucket, k, v []byte) {
|
func (txw *txWriteBuffer) put(bucket, k, v []byte) {
|
||||||
txw.seq[string(bucket)] = false
|
bucketstr := string(bucket)
|
||||||
txw.putSeq(bucket, k, v)
|
txw.bucket2seq[bucketstr] = false
|
||||||
|
txw.putInternal(bucketstr, k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txw *txWriteBuffer) putSeq(bucket, k, v []byte) {
|
func (txw *txWriteBuffer) putSeq(bucket, k, v []byte) {
|
||||||
b, ok := txw.buckets[string(bucket)]
|
// TODO: Add (in tests?) verification whether k>b[len(b)]
|
||||||
|
txw.putInternal(string(bucket), k, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (txw *txWriteBuffer) putInternal(bucket string, k, v []byte) {
|
||||||
|
b, ok := txw.buckets[bucket]
|
||||||
if !ok {
|
if !ok {
|
||||||
b = newBucketBuffer()
|
b = newBucketBuffer()
|
||||||
txw.buckets[string(bucket)] = b
|
txw.buckets[bucket] = b
|
||||||
}
|
}
|
||||||
b.add(k, v)
|
b.add(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txw *txWriteBuffer) reset() {
|
func (txw *txWriteBuffer) reset() {
|
||||||
txw.txBuffer.reset()
|
txw.txBuffer.reset()
|
||||||
for k := range txw.seq {
|
for k := range txw.bucket2seq {
|
||||||
v, ok := txw.buckets[k]
|
v, ok := txw.buckets[k]
|
||||||
if !ok {
|
if !ok {
|
||||||
delete(txw.seq, k)
|
delete(txw.bucket2seq, k)
|
||||||
} else if v.used == 0 {
|
} else if v.used == 0 {
|
||||||
txw.seq[k] = true
|
txw.bucket2seq[k] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +83,7 @@ func (txw *txWriteBuffer) writeback(txr *txReadBuffer) {
|
|||||||
txr.buckets[k] = wb
|
txr.buckets[k] = wb
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if seq, ok := txw.seq[k]; ok && !seq && wb.used > 1 {
|
if seq, ok := txw.bucket2seq[k]; ok && !seq && wb.used > 1 {
|
||||||
// assume no duplicate keys
|
// assume no duplicate keys
|
||||||
sort.Sort(wb)
|
sort.Sort(wb)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user