Skip to content
Snippets Groups Projects
Commit 3665fee3 authored by ale's avatar ale
Browse files

try to perform backups without killing the server

parent b188f6f9
No related branches found
No related tags found
No related merge requests found
......@@ -84,12 +84,18 @@ func scanner(db *db_client.DatabaseRpcClient, bucketCh chan string, outCh chan R
defer session.Close()
for bucket := range bucketCh {
iter, err := session.Scan(bucket, "", "\xff", -1)
// Call Scan() in batches, to avoid overloading the server.
batchSize := 1000
startKey, endKey := "", "\xff"
for startKey < endKey {
iter, err := session.Scan(bucket, startKey, endKey, batchSize)
if err != nil {
log.Printf("Scan error for bucket %s: %s", bucket, err)
continue
break
}
// Iterate over the results and send them to outCh.
n := 0
for {
var data []byte
key, err := iter.Next(&data)
......@@ -102,6 +108,16 @@ func scanner(db *db_client.DatabaseRpcClient, bucketCh chan string, outCh chan R
Key: key,
Data: data,
}
n++
startKey = key
}
// An empty result means we've reached the end
// of the scan.
if n == 0 {
break
}
// Start the next scan from the next key.
startKey = db_client.IncrementKey(startKey)
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment