-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrycount.go
74 lines (65 loc) · 1.92 KB
/
entrycount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"os"
"io"
"log"
"flag"
"strings"
"runtime"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/util"
)
var (
Trace, Info, Warning, Error *log.Logger
logfile, dbname string
)
func Usage() {
fmt.Println("Fingerprint balanced bucket, store fhash within embeded db")
fmt.Println(" Usage: generate -dbname=db")
}
func Init(errorHandle io.Writer) {
Info = log.New(errorHandle,
"INFO: ",
log.Ldate|log.Ltime|log.Lshortfile)
Error = log.New(errorHandle,
"ERROR: ",
log.Ldate|log.Ltime|log.Lshortfile)
}
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
//_, filename, _, _ := runtime.Caller(1)
//cwd, _ := path.Split(filename)
//libpath = path.Join(cwd, "libs")
//os.Setenv("LD_LIBRARY_PATH", libpath)
flag.StringVar(&dbname, "dbname", "db", "fingerprint db storage name")
flag.StringVar(&logfile, "logfile", "entrycount.log", "file name for logging")
}
func main() {
//Initialization
flag.Parse()
logFile, err := os.OpenFile(logfile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Fatalln("Failed to open log file", err)
}
logHandle := io.MultiWriter(logFile, os.Stdout)
Init(logHandle)
db, _ := leveldb.OpenFile(dbname, nil)
defer db.Close()
var key []byte
var count int
iter := db.NewIterator(util.BytesPrefix([]byte("h-")), nil)
for iter.Next() {
// Remember that the contents of the returned slice
// should not be modified, and only valid until the next call to Next.
key = iter.Key()
lognbit := strings.Split(string(key[:]), "-")[1]
if lognbit != "Inf" {
//fmt.Println(string(key[:]))
count += 1
//mapChan <- &Map{string(key[:]), &value}
}
}
iter.Release()
Info.Println("Total count", count)
}