Skip to content

Commit

Permalink
Allow to write to temporary spaces in read-only mode
Browse files Browse the repository at this point in the history
Closes #1378
  • Loading branch information
locker committed Dec 1, 2016
1 parent f30745e commit 9257178
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/box/box.cc
Expand Up @@ -119,12 +119,11 @@ box_check_slab_alloc_minimal(ssize_t slab_alloc_minimal)
}

void
process_rw(struct request *request, struct tuple **result)
process_rw(struct request *request, struct space *space, struct tuple **result)
{
assert(iproto_type_is_dml(request->type));
rmean_collect(rmean_box, request->type, 1);
try {
struct space *space = space_cache_find(request->space_id);
struct txn *txn = txn_begin_stmt(space);
access_check_space(space, PRIV_W);
struct tuple *tuple;
Expand Down Expand Up @@ -207,7 +206,8 @@ apply_row(struct xstream *stream, struct xrow_header *row)
request_decode_xc(request, (const char *) row->body[0].iov_base,
row->body[0].iov_len);
request->header = row;
process_rw(request, NULL);
struct space *space = space_cache_find(request->space_id);
process_rw(request, space, NULL);
}

struct wal_stream {
Expand Down Expand Up @@ -536,7 +536,8 @@ boxk(enum iproto_type type, uint32_t space_id, const char *format, ...)
default:
unreachable();
}
process_rw(request, NULL);
struct space *space = space_cache_find(space_id);
process_rw(request, space, NULL);
}

int
Expand Down Expand Up @@ -599,8 +600,11 @@ int
box_process1(struct request *request, box_tuple_t **result)
{
try {
box_check_writable();
process_rw(request, result);
/* Allow to write to temporary spaces in read-only mode. */
struct space *space = space_cache_find(request->space_id);
if (!space->def.opts.temporary)
box_check_writable();
process_rw(request, space, result);
return 0;
} catch (Exception *e) {
return -1;
Expand Down
27 changes: 27 additions & 0 deletions test/box/temp_spaces.result
Expand Up @@ -72,6 +72,33 @@ s.temporary
---
- true
...
-- check that temporary space can be modified in read-only mode (gh-1378)
box.cfg{read_only=true}
---
...
box.cfg.read_only
---
- true
...
s:insert{2, 3, 4}
---
- [2, 3, 4]
...
s:get{2}
---
- [2, 3, 4]
...
s:len()
---
- 2
...
box.cfg{read_only=false}
---
...
box.cfg.read_only
---
- false
...
env = require('test_run')
---
...
Expand Down
9 changes: 9 additions & 0 deletions test/box/temp_spaces.test.lua
Expand Up @@ -28,6 +28,15 @@ s.temporary
_ = _space:update(s.id, {{'=', FLAGS, ''}})
s.temporary

-- check that temporary space can be modified in read-only mode (gh-1378)
box.cfg{read_only=true}
box.cfg.read_only
s:insert{2, 3, 4}
s:get{2}
s:len()
box.cfg{read_only=false}
box.cfg.read_only

env = require('test_run')
test_run = env.new()
test_run:cmd('restart server default')
Expand Down

0 comments on commit 9257178

Please sign in to comment.