Skip to content

Commit 7ed6edc

Browse files
cydrainJinHai-CN
andauthored
Caiyd 1883 fix rw (#1926)
* #1883 use DiskIO Signed-off-by: yudong.cai <yudong.cai@zilliz.com> * fix logic error Signed-off-by: yudong.cai <yudong.cai@zilliz.com> * update changelog Signed-off-by: yudong.cai <yudong.cai@zilliz.com> * retry CI Signed-off-by: yudong.cai <yudong.cai@zilliz.com> * Update CHANGELOG Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * update changelog Signed-off-by: yudong.cai <yudong.cai@zilliz.com> Co-authored-by: JinHai-CN <hai.jin@zilliz.com>
1 parent c60babe commit 7ed6edc

File tree

4 files changed

+35
-88
lines changed

4 files changed

+35
-88
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Please mark all change in change log and use the issue from GitHub
44

5-
# Milvus 0.8.0 (TBD)
5+
# Milvus 0.8.0 (2020-04-14)
66

77
## Bug
88
- \#1276 SQLite throw exception after create 50000+ partitions in a table
@@ -11,6 +11,7 @@ Please mark all change in change log and use the issue from GitHub
1111
- \#1832 Fix crash in tracing module
1212
- \#1873 Fix index file serialize to incorrect path
1313
- \#1881 Fix bad alloc when index files lost
14+
- \#1883 Fix inserted vectors becomes all zero when index_file_size >= 2GB
1415
- \#1901 Search failed with flat index
1516
- \#1903 Fix invalid annoy result
1617
- \#1910 C++ SDK GetIDsInSegment could not work for large dataset
@@ -36,7 +37,6 @@ Please mark all change in change log and use the issue from GitHub
3637

3738
## Task
3839

39-
4040
# Milvus 0.7.1 (2020-03-29)
4141

4242
## Bug
@@ -707,7 +707,7 @@ Please mark all change in change log and use the issue from GitHub
707707
- MS-37 Add query, cache usage, disk write speed and file data size metrics
708708
- MS-30 Use faiss v1.5.2
709709
- MS-54 cmake: Change Thrift third party URL to github.com
710-
- MS-69 prometheus: add all proposed metrics
710+
- MS-69 Prometheus: add all proposed metrics
711711

712712
## Task
713713

core/src/codecs/default/DefaultVectorsFormat.cpp

Lines changed: 27 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -31,74 +31,44 @@ namespace milvus {
3131
namespace codec {
3232

3333
void
34-
DefaultVectorsFormat::read_vectors_internal(const std::string& file_path, off_t offset, size_t num,
35-
std::vector<uint8_t>& raw_vectors) {
36-
int rv_fd = open(file_path.c_str(), O_RDONLY, 00664);
37-
if (rv_fd == -1) {
34+
DefaultVectorsFormat::read_vectors_internal(const storage::FSHandlerPtr& fs_ptr, const std::string& file_path,
35+
off_t offset, size_t num, std::vector<uint8_t>& raw_vectors) {
36+
if (!fs_ptr->reader_ptr_->open(file_path.c_str())) {
3837
std::string err_msg = "Failed to open file: " + file_path + ", error: " + std::strerror(errno);
3938
ENGINE_LOG_ERROR << err_msg;
40-
throw Exception(SERVER_CANNOT_CREATE_FILE, err_msg);
39+
throw Exception(SERVER_CANNOT_OPEN_FILE, err_msg);
4140
}
4241

4342
size_t num_bytes;
44-
if (::read(rv_fd, &num_bytes, sizeof(size_t)) == -1) {
45-
std::string err_msg = "Failed to read from file: " + file_path + ", error: " + std::strerror(errno);
46-
ENGINE_LOG_ERROR << err_msg;
47-
throw Exception(SERVER_WRITE_ERROR, err_msg);
48-
}
43+
fs_ptr->reader_ptr_->read(&num_bytes, sizeof(size_t));
4944

5045
num = std::min(num, num_bytes - offset);
5146

5247
offset += sizeof(size_t); // Beginning of file is num_bytes
53-
int off = lseek(rv_fd, offset, SEEK_SET);
54-
if (off == -1) {
55-
std::string err_msg = "Failed to seek file: " + file_path + ", error: " + std::strerror(errno);
56-
ENGINE_LOG_ERROR << err_msg;
57-
throw Exception(SERVER_WRITE_ERROR, err_msg);
58-
}
48+
fs_ptr->reader_ptr_->seekg(offset);
5949

6050
raw_vectors.resize(num / sizeof(uint8_t));
61-
if (::read(rv_fd, raw_vectors.data(), num) == -1) {
62-
std::string err_msg = "Failed to read from file: " + file_path + ", error: " + std::strerror(errno);
63-
ENGINE_LOG_ERROR << err_msg;
64-
throw Exception(SERVER_WRITE_ERROR, err_msg);
65-
}
51+
fs_ptr->reader_ptr_->read(raw_vectors.data(), num);
6652

67-
if (::close(rv_fd) == -1) {
68-
std::string err_msg = "Failed to close file: " + file_path + ", error: " + std::strerror(errno);
69-
ENGINE_LOG_ERROR << err_msg;
70-
throw Exception(SERVER_WRITE_ERROR, err_msg);
71-
}
53+
fs_ptr->reader_ptr_->close();
7254
}
7355

7456
void
75-
DefaultVectorsFormat::read_uids_internal(const std::string& file_path, std::vector<segment::doc_id_t>& uids) {
76-
int uid_fd = open(file_path.c_str(), O_RDONLY, 00664);
77-
if (uid_fd == -1) {
57+
DefaultVectorsFormat::read_uids_internal(const storage::FSHandlerPtr& fs_ptr, const std::string& file_path,
58+
std::vector<segment::doc_id_t>& uids) {
59+
if (!fs_ptr->reader_ptr_->open(file_path.c_str())) {
7860
std::string err_msg = "Failed to open file: " + file_path + ", error: " + std::strerror(errno);
7961
ENGINE_LOG_ERROR << err_msg;
80-
throw Exception(SERVER_CANNOT_CREATE_FILE, err_msg);
62+
throw Exception(SERVER_CANNOT_OPEN_FILE, err_msg);
8163
}
8264

8365
size_t num_bytes;
84-
if (::read(uid_fd, &num_bytes, sizeof(size_t)) == -1) {
85-
std::string err_msg = "Failed to read from file: " + file_path + ", error: " + std::strerror(errno);
86-
ENGINE_LOG_ERROR << err_msg;
87-
throw Exception(SERVER_WRITE_ERROR, err_msg);
88-
}
66+
fs_ptr->reader_ptr_->read(&num_bytes, sizeof(size_t));
8967

9068
uids.resize(num_bytes / sizeof(segment::doc_id_t));
91-
if (::read(uid_fd, uids.data(), num_bytes) == -1) {
92-
std::string err_msg = "Failed to read from file: " + file_path + ", error: " + std::strerror(errno);
93-
ENGINE_LOG_ERROR << err_msg;
94-
throw Exception(SERVER_WRITE_ERROR, err_msg);
95-
}
69+
fs_ptr->reader_ptr_->read(uids.data(), num_bytes);
9670

97-
if (::close(uid_fd) == -1) {
98-
std::string err_msg = "Failed to close file: " + file_path + ", error: " + std::strerror(errno);
99-
ENGINE_LOG_ERROR << err_msg;
100-
throw Exception(SERVER_WRITE_ERROR, err_msg);
101-
}
71+
fs_ptr->reader_ptr_->close();
10272
}
10373

10474
void
@@ -121,13 +91,13 @@ DefaultVectorsFormat::read(const storage::FSHandlerPtr& fs_ptr, segment::Vectors
12191
const auto& path = it->path();
12292
if (path.extension().string() == raw_vector_extension_) {
12393
std::vector<uint8_t> vector_list;
124-
read_vectors_internal(path.string(), 0, INT64_MAX, vector_list);
94+
read_vectors_internal(fs_ptr, path.string(), 0, INT64_MAX, vector_list);
12595
vectors_read->AddData(vector_list);
12696
vectors_read->SetName(path.stem().string());
12797
}
12898
if (path.extension().string() == user_id_extension_) {
12999
std::vector<segment::doc_id_t> uids;
130-
read_uids_internal(path.string(), uids);
100+
read_uids_internal(fs_ptr, path.string(), uids);
131101
vectors_read->AddUids(uids);
132102
}
133103
}
@@ -144,54 +114,28 @@ DefaultVectorsFormat::write(const storage::FSHandlerPtr& fs_ptr, const segment::
144114

145115
TimeRecorder rc("write vectors");
146116

147-
int rv_fd = open(rv_file_path.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 00664);
148-
if (rv_fd == -1) {
117+
if (!fs_ptr->writer_ptr_->open(rv_file_path.c_str())) {
149118
std::string err_msg = "Failed to open file: " + rv_file_path + ", error: " + std::strerror(errno);
150119
ENGINE_LOG_ERROR << err_msg;
151120
throw Exception(SERVER_CANNOT_CREATE_FILE, err_msg);
152121
}
153122

154123
size_t rv_num_bytes = vectors->GetData().size() * sizeof(uint8_t);
155-
if (::write(rv_fd, &rv_num_bytes, sizeof(size_t)) == -1) {
156-
std::string err_msg = "Failed to write to file: " + rv_file_path + ", error: " + std::strerror(errno);
157-
ENGINE_LOG_ERROR << err_msg;
158-
throw Exception(SERVER_WRITE_ERROR, err_msg);
159-
}
160-
if (::write(rv_fd, vectors->GetData().data(), rv_num_bytes) == -1) {
161-
std::string err_msg = "Failed to write to file: " + rv_file_path + ", error: " + std::strerror(errno);
162-
ENGINE_LOG_ERROR << err_msg;
163-
throw Exception(SERVER_WRITE_ERROR, err_msg);
164-
}
165-
if (::close(rv_fd) == -1) {
166-
std::string err_msg = "Failed to close file: " + rv_file_path + ", error: " + std::strerror(errno);
167-
ENGINE_LOG_ERROR << err_msg;
168-
throw Exception(SERVER_WRITE_ERROR, err_msg);
169-
}
124+
fs_ptr->writer_ptr_->write(&rv_num_bytes, sizeof(size_t));
125+
fs_ptr->writer_ptr_->write((void*)vectors->GetData().data(), rv_num_bytes);
126+
fs_ptr->writer_ptr_->close();
170127

171128
rc.RecordSection("write rv done");
172129

173-
int uid_fd = open(uid_file_path.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 00664);
174-
if (uid_fd == -1) {
130+
if (!fs_ptr->writer_ptr_->open(uid_file_path.c_str())) {
175131
std::string err_msg = "Failed to open file: " + uid_file_path + ", error: " + std::strerror(errno);
176132
ENGINE_LOG_ERROR << err_msg;
177133
throw Exception(SERVER_CANNOT_CREATE_FILE, err_msg);
178134
}
179135
size_t uid_num_bytes = vectors->GetUids().size() * sizeof(segment::doc_id_t);
180-
if (::write(uid_fd, &uid_num_bytes, sizeof(size_t)) == -1) {
181-
std::string err_msg = "Failed to write to file" + rv_file_path + ", error: " + std::strerror(errno);
182-
ENGINE_LOG_ERROR << err_msg;
183-
throw Exception(SERVER_WRITE_ERROR, err_msg);
184-
}
185-
if (::write(uid_fd, vectors->GetUids().data(), uid_num_bytes) == -1) {
186-
std::string err_msg = "Failed to write to file" + uid_file_path + ", error: " + std::strerror(errno);
187-
ENGINE_LOG_ERROR << err_msg;
188-
throw Exception(SERVER_WRITE_ERROR, err_msg);
189-
}
190-
if (::close(uid_fd) == -1) {
191-
std::string err_msg = "Failed to close file: " + uid_file_path + ", error: " + std::strerror(errno);
192-
ENGINE_LOG_ERROR << err_msg;
193-
throw Exception(SERVER_WRITE_ERROR, err_msg);
194-
}
136+
fs_ptr->writer_ptr_->write(&uid_num_bytes, sizeof(size_t));
137+
fs_ptr->writer_ptr_->write((void*)vectors->GetUids().data(), uid_num_bytes);
138+
fs_ptr->writer_ptr_->close();
195139

196140
rc.RecordSection("write uids done");
197141
}
@@ -215,7 +159,7 @@ DefaultVectorsFormat::read_uids(const storage::FSHandlerPtr& fs_ptr, std::vector
215159
for (; it != it_end; ++it) {
216160
const auto& path = it->path();
217161
if (path.extension().string() == user_id_extension_) {
218-
read_uids_internal(path.string(), uids);
162+
read_uids_internal(fs_ptr, path.string(), uids);
219163
}
220164
}
221165
}
@@ -240,7 +184,7 @@ DefaultVectorsFormat::read_vectors(const storage::FSHandlerPtr& fs_ptr, off_t of
240184
for (; it != it_end; ++it) {
241185
const auto& path = it->path();
242186
if (path.extension().string() == raw_vector_extension_) {
243-
read_vectors_internal(path.string(), offset, num_bytes, raw_vectors);
187+
read_vectors_internal(fs_ptr, path.string(), offset, num_bytes, raw_vectors);
244188
}
245189
}
246190
}

core/src/codecs/default/DefaultVectorsFormat.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ class DefaultVectorsFormat : public VectorsFormat {
5555

5656
private:
5757
void
58-
read_vectors_internal(const std::string&, off_t, size_t, std::vector<uint8_t>&);
58+
read_vectors_internal(const storage::FSHandlerPtr& fs_ptr, const std::string& file_path, off_t offset, size_t num,
59+
std::vector<uint8_t>& raw_vectors);
5960

6061
void
61-
read_uids_internal(const std::string&, std::vector<segment::doc_id_t>&);
62+
read_uids_internal(const storage::FSHandlerPtr& fs_ptr, const std::string& file_path,
63+
std::vector<segment::doc_id_t>& uids);
6264

6365
private:
6466
std::mutex mutex_;

core/src/utils/Error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ constexpr ErrorCode SERVER_CANNOT_CREATE_FILE = ToServerErrorCode(9);
6363
constexpr ErrorCode SERVER_CANNOT_DELETE_FOLDER = ToServerErrorCode(10);
6464
constexpr ErrorCode SERVER_CANNOT_DELETE_FILE = ToServerErrorCode(11);
6565
constexpr ErrorCode SERVER_BUILD_INDEX_ERROR = ToServerErrorCode(12);
66+
constexpr ErrorCode SERVER_CANNOT_OPEN_FILE = ToServerErrorCode(13);
6667

6768
constexpr ErrorCode SERVER_COLLECTION_NOT_EXIST = ToServerErrorCode(100);
6869
constexpr ErrorCode SERVER_INVALID_COLLECTION_NAME = ToServerErrorCode(101);

0 commit comments

Comments
 (0)