Skip to content

Commit

Permalink
Merge pull request #26 from magoo/dev/shards
Browse files Browse the repository at this point in the history
Adding Shard Name fixing #24
  • Loading branch information
magoo authored Sep 21, 2016
2 parents fadf089 + 742efd2 commit 7e6f610
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ AUTHTABLES_HOST=redis
AUTHTABLES_PORT=6379
AUTHTABLES_LOGLEVEL=debug
AUTHTABLES_BLOOMSIZE=1000000000
AUTHTABLES_SHARD=
#AUTHTABLES_PW=
15 changes: 8 additions & 7 deletions authtables.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func main() {
func getRecordHashesFromRecord(rec Record) (recordhashes RecordHashes) {

rh := RecordHashes{
uid: []byte(rec.Uid),
uidMID: []byte(fmt.Sprintf("%s:%s", rec.Uid, rec.Mid)),
uidIP: []byte(fmt.Sprintf("%s:%s", rec.Uid, rec.Ip)),
uidALL: []byte(fmt.Sprintf("%s:%s:%s", rec.Uid, rec.Ip, rec.Mid)),
ipMID: []byte(fmt.Sprintf("%s:%s", rec.Ip, rec.Mid)),
midIP: []byte(fmt.Sprintf("%s:%s", rec.Mid, rec.Ip)),
uid: []byte(c.Shard + rec.Uid),
uidMID: []byte(fmt.Sprintf(c.Shard + "%s:%s", rec.Uid, rec.Mid)),
uidIP: []byte(fmt.Sprintf(c.Shard + "%s:%s", rec.Uid, rec.Ip)),
uidALL: []byte(fmt.Sprintf(c.Shard + "%s:%s:%s", rec.Uid, rec.Ip, rec.Mid)),
ipMID: []byte(fmt.Sprintf(c.Shard + "%s:%s", rec.Ip, rec.Mid)),
midIP: []byte(fmt.Sprintf(c.Shard + "%s:%s", rec.Mid, rec.Ip)),
}

return rh
Expand Down Expand Up @@ -243,7 +243,8 @@ func loadRecords() {
for {
var keys []string
var err error
keys, cursor, err = client.Scan(cursor, "", 10).Result()
//The shard name is pulled from config. We don't want to waste time on records that won't be asked of us.
keys, cursor, err = client.Scan(cursor, c.Shard + "*", 10).Result()
if err != nil {
log.Error("Could not connect to database. Continuing without records")
break
Expand Down
13 changes: 9 additions & 4 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (

//Configuration holds data cleaned from our ENV variables or passed through cmd line
type Configuration struct {
Host string
Port string
Password string
Loglevel string
Host string
Port string
Password string
Loglevel string
BloomSize uint
Shard string
}

//Global access to configuration variables
Expand All @@ -32,6 +33,9 @@ func readConfig() (c Configuration) {
var flagBloomSize uint
d, _ := strconv.ParseUint(os.Getenv("AUTHTABLES_BLOOMSIZE"), 0, 32)
flag.UintVar(&flagBloomSize, "bloomsize", uint(d), "size of bloom filter (default 1e9)")
var flagShard string
flag.StringVar(&flagShard, "shard", os.Getenv("AUTHTABLES_SHARD"), "name of this shard (prefix's keys within redis)")

flag.Parse()

if (flagHost == "" || flagPort == "" || flagLoglevel == "" || flagBloomSize == 0) {
Expand All @@ -47,6 +51,7 @@ func readConfig() (c Configuration) {
configuration.Password = flagPW
configuration.Loglevel = flagLoglevel
configuration.BloomSize = flagBloomSize
configuration.Shard = flagShard

return configuration
}

0 comments on commit 7e6f610

Please sign in to comment.