1
0
Fork 0
forked from forgejo/forgejo

Integrate public as bindata optionally (#293)

* Dropped unused codekit config

* Integrated dynamic and static bindata for public

* Ignore public bindata

* Add a general generate make task

* Integrated flexible public assets into web command

* Updated vendoring, added all missiong govendor deps

* Made the linter happy with the bindata and dynamic code

* Moved public bindata definition to modules directory

* Ignoring the new bindata path now

* Updated to the new public modules import path

* Updated public bindata command and drop the new prefix
This commit is contained in:
Thomas Boerger 2016-11-29 17:26:36 +01:00 committed by Lunny Xiao
parent 4680c349dd
commit b6a95a8cb3
691 changed files with 305318 additions and 1272 deletions

6
vendor/github.com/pingcap/go-themis/oracle/oracle.go generated vendored Normal file
View file

@ -0,0 +1,6 @@
package oracle
type Oracle interface {
GetTimestamp() (uint64, error)
IsExpired(lockTimestamp uint64, TTL uint64) bool
}

View file

@ -0,0 +1,42 @@
package oracles
import (
"sync"
"time"
"github.com/pingcap/go-themis/oracle"
)
const epochShiftBits = 18
var _ oracle.Oracle = &localOracle{}
type localOracle struct {
mu sync.Mutex
lastTimeStampTs int64
n int64
}
// NewLocalOracle creates an Oracle that use local time as data source.
func NewLocalOracle() oracle.Oracle {
return &localOracle{}
}
func (l *localOracle) IsExpired(lockTs uint64, TTL uint64) bool {
beginMs := lockTs >> epochShiftBits
return uint64(time.Now().UnixNano()/int64(time.Millisecond)) >= (beginMs + TTL)
}
func (l *localOracle) GetTimestamp() (uint64, error) {
l.mu.Lock()
defer l.mu.Unlock()
ts := (time.Now().UnixNano() / int64(time.Millisecond)) << epochShiftBits
if l.lastTimeStampTs == ts {
l.n++
return uint64(ts + l.n), nil
} else {
l.lastTimeStampTs = ts
l.n = 0
}
return uint64(ts), nil
}

View file

@ -0,0 +1,48 @@
package oracles
import (
"time"
"github.com/juju/errors"
"github.com/ngaut/tso/client"
"github.com/pingcap/go-themis/oracle"
)
const maxRetryCnt = 3
var _ oracle.Oracle = &remoteOracle{}
// remoteOracle is an oracle that use a remote data source.
type remoteOracle struct {
c *client.Client
}
// NewRemoteOracle creates an oracle that use a remote data source.
// Refer https://github.com/ngaut/tso for more details.
func NewRemoteOracle(zks, path string) oracle.Oracle {
return &remoteOracle{
c: client.NewClient(&client.Conf{
ZKAddr: zks,
RootPath: path,
}),
}
}
func (t *remoteOracle) IsExpired(lockTs uint64, TTL uint64) bool {
beginMs := lockTs >> epochShiftBits
// TODO records the local wall time when getting beginMs from TSO
return uint64(time.Now().UnixNano()/int64(time.Millisecond)) >= (beginMs + TTL)
}
// GetTimestamp gets timestamp from remote data source.
func (t *remoteOracle) GetTimestamp() (uint64, error) {
var err error
for i := 0; i < maxRetryCnt; i++ {
ts, e := t.c.GoGetTimestamp().GetTS()
if e == nil {
return uint64((ts.Physical << epochShiftBits) + ts.Logical), nil
}
err = errors.Trace(e)
}
return 0, err
}