-
Notifications
You must be signed in to change notification settings - Fork 10
/
little_bigtable.go
67 lines (56 loc) · 1.61 KB
/
little_bigtable.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
/*
little_bigtable launches the sqlite3 backed Bigtable emulator on the given address.
*/
package main
import (
"context"
"database/sql"
"flag"
"fmt"
"log"
"os"
"runtime"
"github.com/bitly/little_bigtable/bttest"
_ "github.com/mattn/go-sqlite3"
"google.golang.org/grpc"
)
const (
maxMsgSize = 256 * 1024 * 1024 // 256 MiB
version = "0.1.1"
)
func main() {
host := flag.String("host", "localhost", "the address to bind to on the local machine")
port := flag.Int("port", 9000, "the port number to bind to on the local machine")
dbFile := flag.String("db-file", "little_bigtable.db", "path to data file")
showVersion := flag.Bool("version", false, "show version")
ctx := context.Background()
grpc.EnableTracing = false
flag.Parse()
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
if *showVersion {
fmt.Printf("little_bigtable v%s (built w/%s)", version, runtime.Version())
os.Exit(0)
}
if *dbFile == "" {
log.Fatal("missing --db-file")
}
db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?cache=shared", *dbFile))
if err != nil {
log.Fatalf("failed creating sqlite3 connection %v", err)
}
db.SetMaxOpenConns(1)
err = bttest.CreateTables(ctx, db)
if err != nil {
log.Fatalf("%#v", err)
}
opts := []grpc.ServerOption{
grpc.MaxRecvMsgSize(maxMsgSize),
grpc.MaxSendMsgSize(maxMsgSize),
}
srv, err := bttest.NewServer(fmt.Sprintf("%s:%d", *host, *port), db, opts...)
if err != nil {
log.Fatalf("failed to start emulator: %v", err)
}
log.Printf("\"little\" Bigtable emulator running. DB:%s Connect with environment variable BIGTABLE_EMULATOR_HOST=%q", *dbFile, srv.Addr)
select {}
}