Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry-Mao committed Dec 15, 2014
1 parent df8964d commit c69e14e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 56 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Version 1.1 (pending)
## Version 1.2 (Pennding)
## Version 1.1 (2014-12-15)

New Features:
- Add service failover support
- Add golang rpc failver support

Bugfixes:

Expand Down
117 changes: 62 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $ vim /etc/profile.d/golang.sh
# export GOROOT=/usr/local/go
# export PATH=$PATH:$GOROOT/bin
# export GOPATH=/data/apps/go
$ source /etc/profile.d/gopush.sh
$ source /etc/profile.d/golang.sh
# download the code
$ go get -u github.com/Terry-Mao/gosnowflake
# find the dir
Expand All @@ -37,19 +37,33 @@ $ ./gosnowflake -conf=./gosnowflake.conf
# for help
$ ./gosnowflake -h
# test
$ cd $GOPATH/src/github.com/Terry-Mao/gosnowflake/test
$ go build
$ ./test
$ cd $GOPATH/src/github.com/Terry-Mao/gosnowflake/client
$ go test -conf=./test-examples.conf
```

## Document
```sh
[base]
# If the master process is run as root, then gosnowflake will setuid()/setgid()
# to USER/GROUP. If GROUP is not specified, then gosnowflake uses the same name as
# USER. By default it's nobody user and nobody or nogroup group.
# user maojian
# gosnowflake configuration file example

# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1kb => 1024 bytes
# 1mb => 1024*1024 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.

# Note on units: when time duration is needed, it is possible to specify
# it in the usual form of 1s 5M 4h and so forth:
#
# 1s => 1000 * 1000 * 1000 nanoseconds
# 1m => 60 seconds
# 1h => 60 minutes
#
# units are case insensitive so 1h 1H are all the same.

[base]
# When running daemonized, gosnowflake writes a pid file in
# /tmp/gosnowflake.pid by default. You can specify a custom pid file
# location here.
Expand All @@ -63,16 +77,28 @@ pid /tmp/gosnowflake.pid

# By default gosnowflake listens for connections from all the network interfaces
# available on the server on 8080 port. It is possible to listen to just one or
# multiple interfaces using the "websocket.bind" configuration directive,
# multiple interfaces using the "rpc.bind" configuration directive,
# followed by one or more IP addresses and port.
#
# Examples:
#
# Note this directive is only support "websocket" protocol
# Note this directive is only support "golang rpc" protocol
# rpc.bind 192.168.1.100:8080,10.0.0.1:8080
# rpc.bind 127.0.0.1:8080
# rpc.bind :8080

# By default gosnowflake thrift listens for connections from all the network interfaces
# available on the server on 8080 port. It is possible to listen to just one or
# multiple interfaces using the "rpc.bind" configuration directive,
# followed by one or more IP addresses and port.
#
# Examples:
#
# Note this directive is only support "thrift" protocol
# thrift.bind 192.168.1.100:8080,10.0.0.1:8080
# thrift.bind 127.0.0.1:8080
# thrift.bind :8080

# This is used by gosnowflake service profiling (pprof).
# By default gosnowflake pprof listens for connections from local interfaces on 6971
# port. It's not safty for listening internet IP addresses.
Expand Down Expand Up @@ -101,6 +127,9 @@ pid /tmp/gosnowflake.pid
# Note that you must specify a directory here, not a file name.
dir ./

# Log4go configuration path
log ./log.xml

################################## ZOOKEEPER ##################################
[zookeeper]
# The zookeeper cluster section. When gosnowflake start, it will register data
Expand Down Expand Up @@ -135,11 +164,13 @@ path /gosnowflake-servers
datacenter 0

# register which worker, must be unique in one datacenter.
# multiple worker id register can split by a ",".
# Examples:
#
# worker 0
# worker 0,1,2
worker 0,1,2

```

## RPC API
Expand All @@ -155,51 +186,18 @@ worker 0,1,2
## Usage

```go
package main

import (
"fmt"
"net/rpc"
"github.com/golang/glog"
)

func main() {
addr := "localhost:8080"
cli, err := rpc.Dial("tcp", addr)
if err != nil {
glog.Errorf("rcp.Dial(\"tcp\", \"%s\") error(%v)", addr, err)
return
}
defer cli.Close()
// get snowflake id by workerId
id := int64(0)
workerId := 0
if err = cli.Call("SnowflakeRPC.NextId", workerId, &id); err != nil {
glog.Errorf("rpc.Call(\"SnowflakeRPC.NextId\", %d, &id) error(%v)", workerId, err)
return
}
glog.Infof("nextid: %d\n", id)
// get datacenter id
datacenterId := int64(0)
if err = cli.Call("SnowflakeRPC.DatacenterId", 0, &datacenterId); err != nil {
glog.Errorf("rpc.Call(\"SnowflakeRPC.DatacenterId\", 0, &datacenterId) error(%v)", err)
return
}
glog.Infof("datacenterid: %d\n", datacenterId)
// get current timestamp
timestamp := int64(0)
if err = cli.Call("SnowflakeRPC.Timestamp", 0, &timestamp); err != nil {
glog.Errorf("rpc.Call(\"SnowflakeRPC.Timestamp\", 0, &timestamp) error(%v)", err)
return
}
glog.Infof("timestamp: %d\n", timestamp)
status := 0
if err = cli.Call("SnowflakeRPC.Ping", 0, &status); err != nil {
glog.Errorf("rpc.Call(\"SnowflakeRPC.Ping\", 0, &status) error(%v)", err)
return
}
glog.Infof("status: %d\n", status)
if err := Init(MyConf.ZKServers, MyConf.ZKPath, MyConf.ZKTimeout); err != nil {
panic(err)
}
c := NewClient(MyConf.WorkerId)
defer c.Close()
defer c.Destroy()
time.Sleep(1 * time.Second)
id, err := c.Id()
if err != nil {
panic(err)
}
fmt.Printf("gosnwoflake id: %d\n", id)
```

## Highly Available
Expand All @@ -208,6 +206,15 @@ use `heartbeat` or `keepalived` apply a VIP for the client.

a easy keepalived configration: [here](https://github.com/Terry-Mao/gosnowflake/tree/master/keepalived)

(1.0.1)


use zookeeper for client failover

golang client sdk: [here](https://github.com/Terry-Mao/gosnowflake/tree/master/client)

(1.1)

## LICENSE

`gosnowflake` is is distributed under the terms of the GNU General Public License, version 3.0 [GPLv3](http://www.gnu.org/licenses/gpl.txt)

0 comments on commit c69e14e

Please sign in to comment.