This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
*: expose disk_file that was hidden under dsn_handle_t #172
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0cc1eb1
expose disk_file that was hidden under dsn_handle_t
d4d6f6b
fix
b37407a
seperate file_io APIs from service_api_c
20f180b
fix
30d125f
file_io: replace dsn_file_read/write/write_vector with file_io APIs
6e96a8f
replace dsn_file_open/flush/close with file_io APIs
ff5e81a
Merge branch 'master' into dev1
qinzuoyan d5866ae
Merge branch 'master' into dev1
qinzuoyan 76c7c5a
Merge branch 'master' into dev1
qinzuoyan 66897ec
Merge branch 'master' into dev1
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 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Microsoft Corporation | ||
* | ||
* -=- Robust Distributed System Nucleus (rDSN) -=- | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <dsn/tool-api/task.h> | ||
|
||
namespace dsn { | ||
|
||
// forward declaration | ||
class disk_file; | ||
|
||
/*! | ||
open file | ||
|
||
\param file_name filename of the file. | ||
\param flag flags such as O_RDONLY | O_BINARY used by ::open | ||
\param pmode permission mode used by ::open | ||
|
||
\return file handle | ||
*/ | ||
extern disk_file *dsn_file_open(const char *file_name, int flag, int pmode); | ||
|
||
/*! close the file handle */ | ||
extern error_code dsn_file_close(disk_file *file); | ||
|
||
/*! flush the buffer of the given file */ | ||
extern error_code dsn_file_flush(disk_file *file); | ||
|
||
/*! | ||
read file asynchronously | ||
|
||
\param file file handle | ||
\param buffer read buffer | ||
\param count byte size of the read buffer | ||
\param offset offset in the file to start reading | ||
\param cb callback aio task to be executed on completion | ||
*/ | ||
extern void dsn_file_read(disk_file *file, char *buffer, int count, uint64_t offset, aio_task *cb); | ||
|
||
/*! | ||
write file asynchronously | ||
|
||
\param file file handle | ||
\param buffer write buffer | ||
\param count byte size of the to-be-written content | ||
\param offset offset in the file to start write | ||
\param cb callback aio task to be executed on completion | ||
*/ | ||
extern void | ||
dsn_file_write(disk_file *file, const char *buffer, int count, uint64_t offset, aio_task *cb); | ||
|
||
/*! | ||
write file asynchronously with vector buffers | ||
|
||
\param file file handle | ||
\param buffers write buffers | ||
\param buffer_count number of write buffers | ||
\param offset offset in the file to start write | ||
\param cb callback aio task to be executed on completion | ||
*/ | ||
extern void dsn_file_write_vector(disk_file *file, | ||
const dsn_file_buffer_t *buffers, | ||
int buffer_count, | ||
uint64_t offset, | ||
aio_task *cb); | ||
|
||
} // namespace dsn |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Microsoft Corporation | ||
* | ||
* -=- Robust Distributed System Nucleus (rDSN) -=- | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#include <dsn/tool-api/file_io.h> | ||
|
||
#include "disk_engine.h" | ||
|
||
namespace dsn { | ||
|
||
/*extern*/ disk_file *dsn_file_open(const char *file_name, int flag, int pmode) | ||
{ | ||
return task::get_current_disk()->open(file_name, flag, pmode); | ||
} | ||
|
||
/*extern*/ error_code dsn_file_close(disk_file *file) | ||
{ | ||
return task::get_current_disk()->close(file); | ||
} | ||
|
||
/*extern*/ error_code dsn_file_flush(disk_file *file) | ||
{ | ||
return task::get_current_disk()->flush(file); | ||
} | ||
|
||
/*extern*/ void | ||
dsn_file_read(disk_file *file, char *buffer, int count, uint64_t offset, aio_task *cb) | ||
{ | ||
cb->aio()->buffer = buffer; | ||
cb->aio()->buffer_size = count; | ||
cb->aio()->engine = nullptr; | ||
cb->aio()->file = file; | ||
cb->aio()->file_offset = offset; | ||
cb->aio()->type = AIO_Read; | ||
|
||
task::get_current_disk()->read(cb); | ||
} | ||
|
||
/*extern*/ void | ||
dsn_file_write(disk_file *file, const char *buffer, int count, uint64_t offset, aio_task *cb) | ||
{ | ||
cb->aio()->buffer = (char *)buffer; | ||
cb->aio()->buffer_size = count; | ||
cb->aio()->engine = nullptr; | ||
cb->aio()->file = file; | ||
cb->aio()->file_offset = offset; | ||
cb->aio()->type = AIO_Write; | ||
|
||
task::get_current_disk()->write(cb); | ||
} | ||
|
||
/*extern*/ void dsn_file_write_vector(disk_file *file, | ||
const dsn_file_buffer_t *buffers, | ||
int buffer_count, | ||
uint64_t offset, | ||
aio_task *cb) | ||
{ | ||
cb->aio()->buffer = nullptr; | ||
cb->aio()->buffer_size = 0; | ||
cb->aio()->engine = nullptr; | ||
cb->aio()->file = file; | ||
cb->aio()->file_offset = offset; | ||
cb->aio()->type = AIO_Write; | ||
for (int i = 0; i < buffer_count; i++) { | ||
if (buffers[i].size > 0) { | ||
cb->_unmerged_write_buffers.push_back(buffers[i]); | ||
cb->aio()->buffer_size += buffers[i].size; | ||
} | ||
} | ||
|
||
task::get_current_disk()->write(cb); | ||
} | ||
|
||
} // namespace dsn |
Oops, something went wrong.
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.
这个dsn_file_read、dsn_file_wrte和dsn_file_write_vector这三个c接口可以和async_calls.h中file namespace下的几个接口整合一下。这样我们就不用保留两套异步的文件接口了。
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.
这一改改的有点大,我怕扯到蛋...我尽量看看