Merge branch 'master' into boltdb

This commit is contained in:
Barak Michener 2014-08-20 17:37:30 -04:00
commit 77b72e7189
5 changed files with 37 additions and 14 deletions

View file

@ -126,7 +126,7 @@ var (
databasePath = flag.String("dbpath", "/tmp/testdb", "Path to the database.") databasePath = flag.String("dbpath", "/tmp/testdb", "Path to the database.")
databaseBackend = flag.String("db", "memstore", "Database Backend.") databaseBackend = flag.String("db", "memstore", "Database Backend.")
replicationBackend = flag.String("replication", "single", "Replication method.") replicationBackend = flag.String("replication", "single", "Replication method.")
host = flag.String("host", "0.0.0.0", "Host to listen on (defaults to all).") host = flag.String("host", "127.0.0.1", "Host to listen on (defaults to all).")
loadSize = flag.Int("load_size", 10000, "Size of triplesets to load") loadSize = flag.Int("load_size", 10000, "Size of triplesets to load")
port = flag.String("port", "64210", "Port to listen on.") port = flag.String("port", "64210", "Port to listen on.")
readOnly = flag.Bool("read_only", false, "Disable writing via HTTP.") readOnly = flag.Bool("read_only", false, "Disable writing via HTTP.")

View file

@ -39,7 +39,7 @@ All command line flags take precedence over the configuration file.
#### **`listen_host`** #### **`listen_host`**
* Type: String * Type: String
* Default: "0.0.0.0" * Default: "127.0.0.1"
The hostname or IP address for Cayley's HTTP server to listen on. Defaults to all interfaces. The hostname or IP address for Cayley's HTTP server to listen on. Defaults to all interfaces.

View file

@ -62,7 +62,7 @@ Just as before:
And you'll see a message not unlike And you'll see a message not unlike
```bash ```bash
Cayley now listening on 0.0.0.0:64210 Cayley now listening on 127.0.0.1:64210
``` ```
If you visit that address (often, [http://localhost:64210](http://localhost:64210)) you'll see the full web interface and also have a graph ready to serve queries via the [HTTP API](/docs/HTTP.md) If you visit that address (often, [http://localhost:64210](http://localhost:64210)) you'll see the full web interface and also have a graph ready to serve queries via the [HTTP API](/docs/HTTP.md)

View file

@ -210,6 +210,7 @@ func runIteratorToArrayNoTags(it graph.Iterator, ses *Session, limit int) []stri
func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Value, this otto.FunctionCall, limit int) { func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Value, this otto.FunctionCall, limit int) {
count := 0 count := 0
it, _ = it.Optimize() it, _ = it.Optimize()
glog.V(2).Infoln(it.DebugString(0))
for { for {
select { select {
case <-ses.kill: case <-ses.kill:

View file

@ -22,6 +22,7 @@ import (
"time" "time"
"github.com/robertkrimen/otto" "github.com/robertkrimen/otto"
_ "github.com/robertkrimen/otto/underscore"
"github.com/google/cayley/graph" "github.com/google/cayley/graph"
"github.com/google/cayley/query" "github.com/google/cayley/query"
@ -93,8 +94,11 @@ func (s *Session) SendResult(r *Result) bool {
if s.limit >= 0 && s.limit == s.count { if s.limit >= 0 && s.limit == s.count {
return false return false
} }
s.envLock.Lock()
kill := s.kill
s.envLock.Unlock()
select { select {
case <-s.kill: case <-kill:
return false return false
default: default:
} }
@ -111,7 +115,6 @@ func (s *Session) SendResult(r *Result) bool {
} }
func (s *Session) runUnsafe(input interface{}) (otto.Value, error) { func (s *Session) runUnsafe(input interface{}) (otto.Value, error) {
s.kill = make(chan struct{})
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
if r == ErrKillTimeout { if r == ErrKillTimeout {
@ -125,25 +128,41 @@ func (s *Session) runUnsafe(input interface{}) (otto.Value, error) {
// Use buffered chan to prevent blocking. // Use buffered chan to prevent blocking.
s.env.Interrupt = make(chan func(), 1) s.env.Interrupt = make(chan func(), 1)
ready := make(chan struct{})
done := make(chan struct{})
if s.timeout >= 0 { if s.timeout >= 0 {
go func() { go func() {
time.Sleep(s.timeout) time.Sleep(s.timeout)
<-ready
select {
case <-done:
return
default:
close(s.kill) close(s.kill)
s.envLock.Lock() s.envLock.Lock()
defer s.envLock.Unlock() defer s.envLock.Unlock()
s.kill = nil
if s.env != nil { if s.env != nil {
s.env.Interrupt <- func() { s.env.Interrupt <- func() {
panic(ErrKillTimeout) panic(ErrKillTimeout)
} }
s.env = s.emptyEnv s.env = s.emptyEnv
} }
return
}
}() }()
} }
s.envLock.Lock() s.envLock.Lock()
env := s.env env := s.env
if s.kill == nil {
s.kill = make(chan struct{})
}
s.envLock.Unlock() s.envLock.Unlock()
return env.Run(input) close(ready)
out, err := env.Run(input)
close(done)
return out, err
} }
func (s *Session) ExecInput(input string, out chan interface{}, limit int) { func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
@ -254,8 +273,11 @@ func (s *Session) GetJson() ([]interface{}, error) {
if s.err != nil { if s.err != nil {
return nil, s.err return nil, s.err
} }
s.envLock.Lock()
kill := s.kill
s.envLock.Unlock()
select { select {
case <-s.kill: case <-kill:
return nil, ErrKillTimeout return nil, ErrKillTimeout
default: default:
return s.dataOutput, nil return s.dataOutput, nil