Commit bfeb87e7 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 99b11e6e
// zsha1 - compute sha1 of whole latest objects stream in a ZODB database
package main
import (
"context"
"crypto/sha1"
"log"
"fmt"
"os"
"time"
"lab.nexedi.com/kirr/neo/go/zodb"
_ "lab.nexedi.com/kirr/neo/go/zodb/wks"
)
func main() {
url := os.Args[1] // XXX dirty
bg := context.Background()
stor, err := zodb.OpenStorageURL(bg, url)
if err != nil {
log.Fatal(err)
}
lastTid, err := stor.LastTid(bg)
if err != nil {
log.Fatal(err)
}
before := lastTid + 1 // XXX overflow ?
tstart := time.Now()
m := sha1.New()
oid := zodb.Oid(0)
nread := 0
loop:
for {
xid := zodb.Xid{Oid: oid, XTid: zodb.XTid{Tid: before, TidBefore: true}}
data, _, err := stor.Load(bg, xid)
switch err.(type) {
case nil:
// ok
case *zodb.ErrOidMissing:
break loop
default:
log.Fatal(err)
}
m.Write(data)
nread += len(data)
oid += 1
}
tend := time.Now()
fmt.Printf("%x ; oid=0..%d nread=%d t=%s\n",
m.Sum(nil), oid-1, nread, tend.Sub(tstart))
}
......@@ -7,6 +7,7 @@ from ZODB.utils import p64, u64
import hashlib
import sys
from time import time
def main():
url = sys.argv[1]
......@@ -15,9 +16,11 @@ def main():
last_tid = stor.lastTransaction()
before = p64(u64(last_tid) + 1)
tstart = time()
m = hashlib.sha1()
oid = 0
nread = 0
while 1:
try:
data, serial, _ = stor.loadBefore(p64(oid), before)
......@@ -27,9 +30,13 @@ def main():
#print('%s @%s' % (oid, u64(serial)))
m.update(data)
nread += len(data)
oid += 1
print('%s ; oid=0..%d' % (m.hexdigest(), oid-1))
tend = time()
print('%s ; oid=0..%d nread=%d t=%.3fs' % \
(m.hexdigest(), oid-1, nread, tend - tstart))
if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment