Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to allow pushing on a Stack when this is full #45

Merged
merged 19 commits into from Mar 14, 2017

Conversation

fern4lvarez
Copy link
Owner

@fern4lvarez fern4lvarez commented Jan 28, 2017

Previously (0.1.X), when a Stack is full, PUSH operation is unavailable, returning 406 NOT ACCEPTABLE.

This change provides a new config value, of boolean type:

  • PILADB_PUSH_WHEN_FULL as environment variable.
  • -push-when-full as CLI parameter.

When this value is set to true, PUSH operations on a full Stack will be accepted, removing the bottommost element from the Stack.

This PR also adds a new Sweep method to the Stack, which will remove the bottommost element from the Stack, returning such element and an OK if it was successfull. Note that the method is implemented at the Stack level, but there's no such SWEEP operation from the outside of a Pila.

Given that our concept of a Stack is vertical, with elements
being on top of others, it is more convenient to
have frames up or down, instead of previous or next.
@codecov-io
Copy link

codecov-io commented Jan 28, 2017

Codecov Report

Merging #45 into dev-0.2 will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           dev-0.2    #45   +/-   ##
======================================
  Coverage      100%   100%           
======================================
  Files           18     18           
  Lines          679    756   +77     
======================================
+ Hits           679    756   +77
Impacted Files Coverage Δ
config/vars/vars.go 100% <100%> (ø)
pilad/config.go 100% <100%> (ø)
config/value.go 100% <100%> (ø)
pilad/conn.go 100% <100%> (ø)
pkg/stack/stack.go 100% <100%> (ø)
pila/stack.go 100% <100%> (ø)
pilad/status.go 100% <0%> (ø)
pilad/router.go 100% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e38ba46...3eccc88. Read the comment docs.

@fern4lvarez fern4lvarez changed the base branch from master to dev-0.2 February 9, 2017 10:12
@fern4lvarez
Copy link
Owner Author

fern4lvarez commented Feb 11, 2017

Panic 💣

2017/02/11 22:08:27 
2017/02/11 22:08:27          d8b 888               888 888      
2017/02/11 22:08:27          Y8P 888               888 888      
2017/02/11 22:08:27              888               888 888      
2017/02/11 22:08:27 88888b.  888 888  8888b.   .d88888 88888b.  
2017/02/11 22:08:27 888 "88b 888 888    "88b  d88" 888 888 "88b 
2017/02/11 22:08:27 888  888 888 888 .d888888 888  888 888  888 
2017/02/11 22:08:27 888 d88P 888 888 888  888 Y88b 888 888 d88P 
2017/02/11 22:08:27 88888P"  888 888 "Y888888  "Y88888 88888P"  
2017/02/11 22:08:27 888
2017/02/11 22:08:27 888
2017/02/11 22:08:27 888
2017/02/11 22:08:27 
2017/02/11 22:08:27 Version: 568ea6d5a280ec095200e62cef6b9e56ff6cc78d
2017/02/11 22:08:27 Host:    linux_amd64
2017/02/11 22:08:27 Port:    1205
2017/02/11 22:08:27 PID:     22353
2017/02/11 22:08:27 
2017/02/11 22:08:34 POST /_config/MAX_STACK_SIZE 200 3
2017/02/11 22:08:38 POST /databases/BOOKSHELF/stacks/A 410 database BOOKSHELF is Gone
2017/02/11 22:08:39 POST /databases/BOOKSHELF/stacks/A 410 database BOOKSHELF is Gone
2017/02/11 22:08:45 PUT /databases?name=BOOKSHELF 201
2017/02/11 22:08:50 PUT /databases/BOOKSHELF/stacks?name=A 201
2017/02/11 22:08:52 POST /databases/BOOKSHELF/stacks/A 200 uoo
2017/02/11 22:08:56 POST /databases/BOOKSHELF/stacks/A 200 voo
2017/02/11 22:08:58 POST /databases/BOOKSHELF/stacks/A 200 woo
2017/02/11 22:09:00 POST /databases/BOOKSHELF/stacks/A 406 MAX_STACK_SIZE value reached
2017/02/11 22:09:06 POST /_config/PUSH_WHEN_FULL 200 true
2017/02/11 22:09:13 POST /databases/BOOKSHELF/stacks/A 200 sweep base element: uoo
2017/02/11 22:09:13 POST /databases/BOOKSHELF/stacks/A 200 yoo
2017/02/11 22:09:24 GET /databases/BOOKSHELF/stacks/A 200
2017/02/11 22:09:34 POST /databases/BOOKSHELF/stacks/A 200 sweep base element: voo
2017/02/11 22:09:34 POST /databases/BOOKSHELF/stacks/A 200 eoo
2017/02/11 22:09:37 GET /databases/BOOKSHELF/stacks/A 200
2017/02/11 22:09:43 http: panic serving 127.0.0.1:48624: runtime error: invalid memory address or nil pointer dereference
goroutine 35 [running]:
net/http.(*conn).serve.func1(0xc420118200)
	/usr/local/go/src/net/http/server.go:1491 +0x12a
panic(0x683960, 0xc42000c250)
	/usr/local/go/src/runtime/panic.go:458 +0x243
github.com/fern4lvarez/piladb/pkg/stack.(*Stack).Sweep(0xc4200edae0, 0x0, 0x0, 0xc4200f5d00)
	/home/fernando/src/github.com/fern4lvarez/piladb/pkg/stack/stack.go:100 +0x91
github.com/fern4lvarez/piladb/pila.(*Stack).Sweep(0xc42007f600, 0x1, 0x40, 0xc420120560)
	/home/fernando/src/github.com/fern4lvarez/piladb/pila/stack.go:70 +0x34
main.(*Conn).checkMaxStackSize.func1(0x7f6fe0, 0xc4201281a0, 0xc42012e870, 0xc42007f600)
	/home/fernando/src/github.com/fern4lvarez/piladb/pilad/config.go:146 +0x2eb
main.(*Conn).stackHandler.func1(0x7f6fe0, 0xc4201281a0, 0xc42012e870)
	/home/fernando/src/github.com/fern4lvarez/piladb/pilad/conn.go:247 +0x434
net/http.HandlerFunc.ServeHTTP(0xc4200ecc20, 0x7f6fe0, 0xc4201281a0, 0xc42012e870)
	/usr/local/go/src/net/http/server.go:1726 +0x44
github.com/fern4lvarez/piladb/vendor/github.com/gorilla/mux.(*Router).ServeHTTP(0xc420014910, 0x7f6fe0, 0xc4201281a0, 0xc42012e870)
	/home/fernando/src/github.com/fern4lvarez/piladb/vendor/github.com/gorilla/mux/mux.go:114 +0x10d
net/http.serverHandler.ServeHTTP(0xc42007ee00, 0x7f6fe0, 0xc4201281a0, 0xc42012e690)
	/usr/local/go/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc420118200, 0x7f75e0, 0xc4201225c0)
	/usr/local/go/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:2293 +0x44d

How to reproduce?

make pilad
curl -s -XPOST 127.0.0.1:1205/_config/MAX_STACK_SIZE -d '{"element":3}'| jq '.'
curl -s -XPUT "localhost:1205/databases?name=BOOKSHELF" | jq '.'
curl -s -XPUT "localhost:1205/databases/BOOKSHELF/stacks?name=A" | jq '.'
curl -XPOST localhost:1205/databases/BOOKSHELF/stacks/A -d '{"element":"uoo"}'
curl -XPOST localhost:1205/databases/BOOKSHELF/stacks/A -d '{"element":"voo"}'
curl -XPOST localhost:1205/databases/BOOKSHELF/stacks/A -d '{"element":"woo"}'
curl -s -XPOST 127.0.0.1:1205/_config/PUSH_WHEN_FULL -d '{"element":true}'| jq '.'
curl -XPOST localhost:1205/databases/BOOKSHELF/stacks/A -d '{"element":"yoo"}'
curl -XPOST localhost:1205/databases/BOOKSHELF/stacks/A -d '{"element":"eoo"}'
curl -XPOST localhost:1205/databases/BOOKSHELF/stacks/A -d '{"element":"qoo"}'   # 💣 HERE

@fern4lvarez fern4lvarez changed the title Add option to rotate Stack elements when pushing on a full one Add option allow pushing on a Stack when this is empty Feb 13, 2017
@fern4lvarez fern4lvarez added this to the 0.2 milestone Feb 13, 2017
@fern4lvarez fern4lvarez changed the title Add option allow pushing on a Stack when this is empty Add option to allow pushing on a Stack when this is full Feb 13, 2017
@fern4lvarez fern4lvarez merged commit 649d15d into dev-0.2 Mar 14, 2017
@fern4lvarez fern4lvarez deleted the rotate-when-full branch March 14, 2017 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants