Commit Graph

323 Commits

Author SHA1 Message Date
Ethan Buchman 9997e3a3b4 Merge pull request #54 from tendermint/develop
common: WriteFileAtomic use tempfile in current dir
2017-09-22 13:23:12 -04:00
Ethan Buchman 35838b6af8 changeloge, version 2017-09-22 13:22:02 -04:00
Ethan Buchman 3d98504c4c common: WriteFileAtomic use tempfile in current dir 2017-09-22 13:20:13 -04:00
Zach Ramsay 2681f32bdd circle: add metalinter to test 2017-09-22 12:35:52 -04:00
Zach Ramsay 3c57c24921 linting: next round of fixes 2017-09-22 12:14:27 -04:00
Zach Ramsay d6e03d2368 linting: add to Makefile & do some fixes 2017-09-22 11:42:29 -04:00
Ethan Buchman 2130c329eb Merge pull request #46 from tendermint/develop
v0.3.0
2017-09-22 09:41:12 -04:00
Ethan Buchman bffe6744ec changelog 2017-09-22 09:38:58 -04:00
Ethan Buchman c3108f14c8 Merge pull request #52 from tendermint/573-wal-issues
call fsync after flush
2017-09-22 09:35:52 -04:00
Anton Kaliaev d71d1394ec
call fsync after flush (Refs #573)
short: flushing the bufio buffer is not enough to ensure data
consistency.

long:
Saving an entry to the WAL calls writeLine to append data to the
autofile group backing the WAL, then calls group.Flush() to flush that
data to persistent storage. group.Flush() in turn proxies to
headBuf.flush(), flushing the active bufio.BufferedWriter. However,
BufferedWriter wraps a Writer, not another BufferedWriter, and the way
it flushes is by calling io.Writer.Write() to clear the BufferedWriter's
buffer. The io.Writer we're wrapping here is AutoFile, whose Write
method calls os.File.Write(), performing an unbuffered write to the
operating system, where, I assume, it sits in the OS buffers awaiting
sync. This means that Wal.Save does not, in fact, ensure the saved
operation is synced to disk before returning.
2017-09-21 16:11:28 -07:00
Anton Kaliaev 246082368a add changelog entry [ci skip] 2017-09-20 02:49:51 -04:00
Anton Kaliaev 65a07b80a3 change logger interface to not return errors (Refs #50)
See https://github.com/go-kit/kit/issues/164 for discussion of why
kitlog returns an error.

```
Package log is designed to be used for more than simple application info/warning/error logging; it's suitable for log-structured data in an e.g. Lambda architecture, where each invocation is important. I agree with you that if we were doing only application logging the error would be more noise than signal. But the scope of the package is larger than that.
```

Since we are doing only application logging and we're not checking
errors, it is safe to get rid them.
2017-09-20 02:49:51 -04:00
Ethan Buchman 9a2438e0dc common: Fingerprint comment 2017-09-20 02:49:51 -04:00
Ethan Buchman 4e955434aa Merge pull request #48 from tendermint/log_tweak
Log tweak
2017-09-16 00:40:44 -04:00
Jae Kwon 3a36776d4a Reorder file for grokability 2017-09-10 18:45:20 -07:00
Ethan Buchman bfec1ff1cd bump version to 0.3.0 2017-08-25 16:58:59 -04:00
Ethan Buchman bdfd978b68 update changelog 2017-08-25 16:58:37 -04:00
Ethan Buchman 8f1dea89f5 db: fix memdb iterator 2017-08-25 16:35:37 -04:00
Ethan Buchman fe08fc00c8 Merge pull request #34 from orijtech/develop
common/IsDirEmpty: do not mask non-existance errors
2017-08-25 16:01:30 -04:00
Ethan Buchman 271145ee72 Merge pull request #32 from tendermint/bugfix/write-file-atomic
Fix rename /root/.tendermint_test/consensus_replay_test/priv_validator.json.new /root/.tendermint_test/consensus_replay_test/priv_validator.json: no such file or directory
2017-08-25 15:58:09 -04:00
Anton Kaliaev 956966e658
add missing validator package to glide.yaml 2017-08-11 16:36:26 -04:00
Ethan Buchman 20c7a8f035 Merge pull request #31 from tendermint/bugfix/escape-syntax-for-base-16-hashes
[pubsub/query] quote values using single quotes
2017-08-11 12:33:48 -04:00
Anton Kaliaev fa990f0803
add test case for hex 2017-08-10 19:46:59 -04:00
Emmanuel Odeke b4a51871b9
common/IsDirEmpty: do not mask non-existance errors
Currently IsDirEmpty returns true, err if it encounters
any error after trying to os.Open the directory.
I noticed this while studying the code and recalled a bug
from an earlier project in which doing the exact same thing
on code without permissions would trip out and falsely report
that the directory was empty.
Given demo.go in https://play.golang.org/p/vhTPU2RiCJ

* Demo:
```shell
$ mkdir -p sample-demo/1 && touch sample-demo/2
$ echo "1st round" && go run demo.go sample-demo
$ sudo chown root sample-demo && sudo chmod 0700 sample-demo
$ echo "2nd round" && go run demo.go sample-demo
```

That then prints out
```shell
1st round
original:: empty: false err: <nil>
updated::  empty: false err: <nil>
2nd round
original:: empty: true err: open data/: permission denied
updated::  empty: false err: open data/: permission denied
```

where in "2nd round", the original code falsely reports that
the directory is empty but that's a permission error.

I could write a code test for it, but that test requires me to change
users and switch to root as a Go user so no point in complicating our
tests, but otherwise it is a 1-to-1 translation between shell and Go.
2017-08-04 02:22:17 -06:00
Ethan Frey 75372988e7 Merge pull request #33 from orijtech/http-utils
http: http-utils added after extraction
2017-08-02 19:47:10 +02:00
Emmanuel Odeke d67a621715
http: http-utils added after extraction
Found common http utils that were being multiply duplicated across
many libraries and since am moving things in basecoin/unstable to
add for more functionality, it's better to put them in one
place.

Utilities and tests added:
- [X] FparseJSON
- [X] FparseAndValidateJSON
- [X] ParseRequestJSON
- [X] ParseAndValidateRequestJSON
- [X] WriteCode
- [X] WriteError
- [X] WriteSuccess
- [X] ErrorResponse

During review from @ethanfrey, made updates:
* Removed tt.want since it was a distraction/artifact that made
the reviewer think the tests weren't testing for both failed
and passed results.
* Added ErrorWithCode as WithCode is a common options pattern
in Go that could cause confusion:
  ErrorWithCode(error, int) ErrorResponse
* Using json.NewDecoder(io.Reader) error instead of
ioutil.ReadAll(io.Reader) to slurp all the bytes.
* Added more test scenarios to achieve 100% coverage of http.go
2017-08-02 11:38:52 -06:00
Anton Kaliaev d1ca2c6f83
[common] add a test for WriteFileAtomic 2017-07-28 11:40:21 -04:00
Anton Kaliaev b25aa3b472
[common] do not create {filePath}.bak in WriteFileAtomic
We use WriteFileAtomic in two places:

```
p2p/addrbook.go
338:    err = cmn.WriteFileAtomic(filePath, jsonBytes, 0644)

types/priv_validator.go
162:    err = WriteFileAtomic(privVal.filePath, jsonBytes, 0600)
```

and we don't need .bak in any of the above. We save priv_validator every
10ms and addrbook every 2 min.
2017-07-28 11:40:21 -04:00
Anton Kaliaev 8a51210efc
[common] use temp intead of {filePath}.new
The problem with {filePath}.new is that it is not safe for concurrent
use! Calling this function with the same params results in the following
error:

```
panic: Panicked on a Crisis: rename /root/.tendermint_test/consensus_replay_test/priv_validator.json.new /root/.tendermint_test/consensus_replay_test/priv_validator.json: no such file or directory

goroutine 47860 [running]:
github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common.PanicCrisis(0xcba800, 0xc42152d640)
	/go/src/github.com/tendermint/tendermint/vendor/github.com/tendermint/tmlibs/common/errors.go:33 +0x10f
github.com/tendermint/tendermint/types.(*PrivValidator).save(0xc42235f2c0)
	/go/src/github.com/tendermint/tendermint/types/priv_validator.go:165 +0x159
github.com/tendermint/tendermint/types.(*PrivValidator).signBytesHRS(0xc42235f2c0, 0x6, 0x0, 0xc424e88f03, 0xc429908580, 0xca, 0x155, 0x80, 0xc424e88f00, 0x7f4ecafc88d0, ...)
	/go/src/github.com/tendermint/tendermint/types/priv_validator.go:249 +0x2bb
github.com/tendermint/tendermint/types.(*PrivValidator).SignVote(0xc42235f2c0, 0xc4228c7460, 0xf, 0xc424e88f00, 0x0, 0x0)
	/go/src/github.com/tendermint/tendermint/types/priv_validator.go:186 +0x1a2
github.com/tendermint/tendermint/consensus.(*ConsensusState).signVote(0xc424efd520, 0xc400000002, 0xc422d5e3c0, 0x14, 0x20, 0x1, 0xc4247b6560, 0x14, 0x20, 0x0, ...)
	github.com/tendermint/tendermint/consensus/_test/_obj_test/state.go:1556 +0x35e
github.com/tendermint/tendermint/consensus.(*ConsensusState).signAddVote(0xc424efd520, 0x2, 0xc422d5e3c0, 0x14, 0x20, 0x1, 0xc4247b6560, 0x14, 0x20, 0xc42001b300)
	github.com/tendermint/tendermint/consensus/_test/_obj_test/state.go:1568 +0x200
github.com/tendermint/tendermint/consensus.(*ConsensusState).enterPrecommit(0xc424efd520, 0x6, 0x0)
	github.com/tendermint/tendermint/consensus/_test/_obj_test/state.go:1082 +0x13a4
github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote(0xc424efd520, 0xc424e88780, 0x0, 0x0, 0x39, 0x1dc, 0x28c)
	github.com/tendermint/tendermint/consensus/_test/_obj_test/state.go:1477 +0x1be5
github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote(0xc424efd520, 0xc424e88780, 0x0, 0x0, 0xd7fb00, 0xc42152ce00)
	github.com/tendermint/tendermint/consensus/_test/_obj_test/state.go:1382 +0x93
github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg(0xc424efd520, 0xcb58e0, 0xc42547feb8, 0x0, 0x0, 0x6, 0x0, 0x4, 0xed10ca07e, 0x3077bfea, ...)
	github.com/tendermint/tendermint/consensus/_test/_obj_test/state.go:660 +0x9fc
github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine(0xc424efd520, 0x0)
	github.com/tendermint/tendermint/consensus/_test/_obj_test/state.go:615 +0x5f5
created by github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart
	github.com/tendermint/tendermint/consensus/_test/_obj_test/state.go:332 +0x4a7
exit status 2
FAIL	github.com/tendermint/tendermint/consensus	76.644s
make: *** [test_integrations] Error 1
```

See https://github.com/tendermint/tendermint/pull/568
2017-07-28 11:39:59 -04:00
Anton Kaliaev a6a06f820f
[pubsub/query] quote values using single quotes
This fixes the problem with base-16 encoded values which may start with
digits: 015AB.... In such cases, the parser recognizes them as numbers
but fails to parse because of the follow-up characters (AB).

```
failed to parse tm.events.type=Tx AND hash=136E18F7E4C348B780CF873A0BF43922E5BAFA63:
parse error near digit (line 1 symbol 31 - line 1 symbol 32):
  "6"
```

So, from now on we should quote any values. This seems to be the way
Postgresql has chosen.
2017-07-21 13:20:32 +03:00
Ethan Buchman 2f6f3e6aa7 Merge pull request #28 from tendermint/feature/376-events.v2
New pubsub package plus the query subpackage
2017-07-20 15:03:02 -04:00
Anton Kaliaev 77f6febb03
rename TestClientResubscribes to TestClientSubscribesTwice
test UnsubscribeAll properly
test BufferCapacity getter
2017-07-20 11:46:22 +03:00
Ethan Buchman 3c6c1b7d33 common: ProtocolAndAddress 2017-07-19 15:02:04 -04:00
Anton Kaliaev 992c54253f
fixes from gometalinter review 2017-07-18 11:53:41 +03:00
Anton Kaliaev 17d6091ef4
updates as per Bucky's comments 2017-07-15 13:33:47 +03:00
Anton Kaliaev e664f9c688
use context to provide timeouts! 2017-07-14 14:49:25 +03:00
Anton Kaliaev 0006bfc359
return ErrorOverflow on Subscribe if server is overflowed
> why we need it?

most of our subscribers will be RPC WS subscribers, so if there are too
many, nothing wrong with rejecting to subscribe.

however, consensus reactor must be the first to subscribe, since its
work depends on the pubsub package.
2017-07-14 13:02:32 +03:00
Anton Kaliaev 13207a5927
remove overflow options 2017-07-14 12:32:01 +03:00
Anton Kaliaev 4aa024d843
add more info to error messages 2017-07-12 23:10:36 +03:00
Anton Kaliaev e4f3f9d9bf
remove comment about LRU cache (see comments below)
I've tried https://github.com/hashicorp/golang-lru/tree/master/simplelru today and here are
the results:

with LRU cache:

```
Benchmark10Clients-2                               50000             29021 ns/op         3976 B/op         105 allocs/op
Benchmark100Clients-2                               3000            363432 ns/op        36382 B/op        1005 allocs/op
Benchmark1000Clients-2                               500           2473752 ns/op       360500 B/op       10009 allocs/op
Benchmark10ClientsUsingTheSameQuery-2             300000              4059 ns/op          773 B/op          15 allocs/op
Benchmark100ClientsUsingTheSameQuery-2            500000              4360 ns/op          773 B/op          15 allocs/op
Benchmark1000ClientsUsingTheSameQuery-2           300000              4204 ns/op          773 B/op          15 allocs/op
```

without LRU cache:

```
Benchmark10Clients-2                      200000              5267 ns/op             616 B/op       25 allocs/op
Benchmark100Clients-2                      30000             42134 ns/op            2776 B/op      205 allocs/op
Benchmark1000Clients-2                      3000            552648 ns/op           24376 B/op     2005 allocs/op
Benchmark10ClientsOneQuery-2             1000000              2127 ns/op             462 B/op        9 allocs/op
Benchmark100ClientsOneQuery-2             500000              2353 ns/op             462 B/op        9 allocs/op
Benchmark1000ClientsOneQuery-2            500000              2339 ns/op             462 B/op        9 allocs/op
```

> How were you using the lru cache exactly?

I was adding a KV pair each time there is a match plus checking if
`lru.Contains(key)` before running the actual check (`q.Matches(tags)`).

```
key = fmt.Sprintf("%s/%v", query + tags)
```
2017-07-12 22:52:13 +03:00
Anton Kaliaev 8062ade787
remove all clients (including closing all channels) on shutdown 2017-07-12 13:10:36 +03:00
Anton Kaliaev a99b8a6210
new events package
query parser

use parser compiler to generate query parser

I used https://github.com/pointlander/peg which has a nice API and seems
to be the most popular Golang compiler parser using PEG on Github.

More about PEG:

- https://en.wikipedia.org/wiki/Parsing_expression_grammar
- https://github.com/PhilippeSigaud/Pegged/wiki/PEG-Basics
- https://github.com/PhilippeSigaud/Pegged/wiki/Grammar-Examples

rename

implement query match function

match function

uncomment test lines

add more test cases for query#Matches

fix int case

rename events to pubsub

add comment about cache

assertReceive helper to not block on receive in tests

fix bug with multiple conditions

uncomment benchmark

first results:

```
Benchmark10Clients-2                1000           1305493 ns/op         3957519 B/op     355 allocs/op
Benchmark100Clients-2                100          12278304 ns/op        39571751 B/op    3505 allocs/op
Benchmark1000Clients-2                10         124120909 ns/op        395714004 B/op   35005 allocs/op
```

124ms to publish message to 1000 clients. A lot.

use AST from query.peg.go

separate pubsub and query packages by using Query interface in pubsub

wrote docs and refactor code

updates from Frey's review

refactor type assertion to use type switch

cleanup during shutdown

subscriber should create output channel, not the server

overflow strategies, server buffer capacity

context as the first argument for Publish

log error

introduce Option type

update NewServer comment

move helpers into pubsub_test

increase assertReceive timeout

add query.MustParse

add more false tests for parser

add more false tests for query.Matches

parse numbers as int64 / float64

try our best to convert from other types

add number to panic output

add more comments

save commit

introduce client argument as first argument to Subscribe

> Why we do not specify buffer size on the output channel in Subscribe?

The choice of buffer size of N here depends on knowing the number of
messages server will receive and the number of messages downstream
subscribers will consume. This is fragile: if we publish an additional
message, or if one of the downstream subscribers reads any fewer
messages, we will again have blocked goroutines.

save commit

remove reference counting

fix test

test client resubscribe

test UnsubscribeAll

client options

[pubsub/query] fuzzy testing

do not print msg as it creates data race!
2017-07-12 09:48:01 +03:00
Ethan Buchman efb56aaea7 Merge pull request #25 from tendermint/stderr
CLI Execute Error prints to stderr
2017-06-23 22:22:07 -04:00
Ethan Buchman a28e35fd98 Merge branch 'develop' into stderr 2017-06-23 22:21:36 -04:00
Ethan Buchman bf55624f75 Merge pull request #24 from tendermint/dateparse
common date parsing
2017-06-23 22:20:32 -04:00
Ethan Buchman 7fbe6adf24 Merge branch 'develop' into dateparse 2017-06-23 22:16:37 -04:00
rigel rozanski cc364b14e2 changelog and PR changes 2017-06-20 17:18:55 -04:00
rigel rozanski f3eaf9b870 quickfix 2017-06-20 16:52:22 -04:00
rigel rozanski 34bcb30f1c changelog 2017-06-20 16:40:32 -04:00
rigel rozanski 0a3a08a3bc stderr PR revisions 2017-06-17 18:35:05 -04:00