-
Notifications
You must be signed in to change notification settings - Fork 84
Core: bypass write to pipe for local transactions #672
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
Open
toshic
wants to merge
3
commits into
reverbrain:master
Choose a base branch
from
toshic:local_copy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,14 +171,28 @@ void dnet_state_clean(struct dnet_net_state *st) | |
| dnet_log(st->n, DNET_LOG_NOTICE, "Cleaned state %s, transactions freed: %d", dnet_state_dump_addr(st), num); | ||
| } | ||
|
|
||
| static struct dnet_io_req *dnet_io_req_copy(struct dnet_net_state *st, struct dnet_io_req *orig) | ||
| /* | ||
| * This function makes a copy of io_req to transfer memory ownership to another thread. | ||
| * If target thread is net thread we can just make a copy and properly fill fd params. | ||
| * If target thread is io thread (bypass for local transaction on server side, bypass flag | ||
| * is set to 1) we need to allocate buffer and read fd content info this buffer. | ||
| * Result should looks exactly as if was read from network socket. This CPU IO time is spent | ||
| * in backend's IO pool. | ||
| */ | ||
| static struct dnet_io_req *dnet_io_req_copy(struct dnet_net_state *st, struct dnet_io_req *orig, int bypass) | ||
| { | ||
| void *buf; | ||
| size_t len = 0; | ||
| struct dnet_io_req *r; | ||
| int offset = 0; | ||
| int err = 0; | ||
|
|
||
| buf = r = malloc(sizeof(struct dnet_io_req) + orig->dsize + orig->hsize); | ||
| len = sizeof(struct dnet_io_req) + orig->dsize + orig->hsize; | ||
| if (orig->fd >= 0 && orig->fsize && bypass) { | ||
| len += orig->fsize; | ||
| } | ||
|
|
||
| buf = r = malloc(len); | ||
| if (!r) { | ||
| dnet_log(st->n, DNET_LOG_ERROR, "Not enough memory for io req queue fd: %d : %s %d", orig->fd, strerror(-err), err); | ||
| return NULL; | ||
|
|
@@ -192,7 +206,10 @@ static struct dnet_io_req *dnet_io_req_copy(struct dnet_net_state *st, struct dn | |
|
|
||
| offset = r->hsize; | ||
| memcpy(r->header, orig->header, r->hsize); | ||
| } | ||
| } else if (bypass) { | ||
| r->header = buf + sizeof(struct dnet_io_req); | ||
| r->hsize = 0; | ||
| } | ||
|
|
||
| if (orig->data && orig->dsize) { | ||
| r->data = buf + sizeof(struct dnet_io_req) + offset; | ||
|
|
@@ -203,13 +220,49 @@ static struct dnet_io_req *dnet_io_req_copy(struct dnet_net_state *st, struct dn | |
| } | ||
|
|
||
| if (orig->fd >= 0 && orig->fsize) { | ||
| r->fd = orig->fd; | ||
| r->on_exit = orig->on_exit; | ||
| r->local_offset = orig->local_offset; | ||
| r->fsize = orig->fsize; | ||
| if (bypass) { | ||
| if (r->data == NULL) { | ||
| r->data = buf + sizeof(struct dnet_io_req) + offset; | ||
| } | ||
|
|
||
| err = dnet_read_ll(orig->fd, r->data + r->dsize, orig->fsize, orig->local_offset); | ||
| if (err) { | ||
| dnet_log(st->n, DNET_LOG_ERROR, "Error while reading data: %s %d", strerror(-err), err); | ||
| goto err_out_free; | ||
| } | ||
|
|
||
| r->dsize += orig->fsize; | ||
| r->on_exit = orig->on_exit; | ||
|
|
||
| } else { | ||
| r->fd = orig->fd; | ||
| r->on_exit = orig->on_exit; | ||
| r->local_offset = orig->local_offset; | ||
| r->fsize = orig->fsize; | ||
| } | ||
| } | ||
|
|
||
| if (bypass) { | ||
| /* | ||
| * Fixup request. | ||
| * r->header and r->data are just a pointers to the same buffer. | ||
| * Here r->header could be any size, it depend on function that created io_req. | ||
| * In net thread r->hsize is ALWAYS sizeof(struct dnet_cmd) and r->data points | ||
| * exactly after struct dnet_cmd struct. We need to modify our copy to the same layout | ||
| * because dnet_schedule_io requires it. | ||
| */ | ||
| if (r->hsize != sizeof(struct dnet_cmd)) { | ||
| r->data = r->header + sizeof(struct dnet_cmd); | ||
| r->dsize += r->hsize - sizeof(struct dnet_cmd); | ||
| r->hsize = sizeof(struct dnet_cmd); | ||
| } | ||
| } | ||
|
|
||
| return r; | ||
|
|
||
| err_out_free: | ||
| free(r); | ||
| return NULL; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -221,7 +274,27 @@ static int dnet_io_req_queue(struct dnet_net_state *st, struct dnet_io_req *orig | |
| int err = 0; | ||
| struct dnet_io_req *r; | ||
|
|
||
| r = dnet_io_req_copy(st, orig); | ||
| /* | ||
| * If destination is local node there is no need to copy it via net thread. | ||
| * Here it could be scheduled to the proper IO pool directly. | ||
| * If io_req hold fd instead of data it should be read here. | ||
| */ | ||
| if (st == st->n->st) { | ||
| dnet_log(st->n, DNET_LOG_DEBUG, "Sending to local state: data: 0x%lx data_size: %d", (unsigned long)orig->data, (int)orig->dsize); | ||
|
|
||
| r = dnet_io_req_copy(st, orig, 1); | ||
| if (!r) { | ||
| err = -ENOMEM; | ||
| goto err_out_exit; | ||
| } | ||
|
|
||
| r->st = dnet_state_get(st); | ||
| dnet_schedule_io(st->n, r); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| r = dnet_io_req_copy(st, orig, 0); | ||
| if (!r) { | ||
| err = -ENOMEM; | ||
| goto err_out_exit; | ||
|
|
@@ -336,8 +409,12 @@ ssize_t dnet_send(struct dnet_net_state *st, void *data, uint64_t size) | |
| struct dnet_io_req r; | ||
|
|
||
| memset(&r, 0, sizeof(r)); | ||
| r.data = data; | ||
| r.dsize = size; | ||
| r.header = data; | ||
| r.hsize = sizeof(struct dnet_cmd); | ||
| if (size > r.hsize) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should return |
||
| r.data = data + r.hsize; | ||
| r.dsize = size - r.hsize; | ||
| } | ||
| r.fd = -1; | ||
|
|
||
| return dnet_io_req_queue(st, &r); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
origdoesn't have header, why does it setr->headerhere?