Skip to content

Commit 31833c6

Browse files
committed
fix: post-merge CE fix on windows
1 parent 0c67da6 commit 31833c6

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/ailego/buffer/buffer_pool.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
#include <zvec/ailego/buffer/buffer_pool.h>
22
#include <zvec/core/framework/index_logger.h>
33

4+
#if defined(_MSC_VER)
5+
static ssize_t zvec_pread(int fd, void *buf, size_t count, size_t offset) {
6+
HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
7+
if (handle == INVALID_HANDLE_VALUE) return -1;
8+
OVERLAPPED ov = {};
9+
ov.Offset = static_cast<DWORD>(offset & 0xFFFFFFFF);
10+
ov.OffsetHigh = static_cast<DWORD>(offset >> 32);
11+
DWORD bytes_read = 0;
12+
if (!ReadFile(handle, buf, static_cast<DWORD>(count), &bytes_read, &ov)) {
13+
return -1;
14+
}
15+
return static_cast<ssize_t>(bytes_read);
16+
}
17+
#endif
18+
419
namespace zvec {
520
namespace ailego {
621

@@ -167,13 +182,23 @@ void LPMap::recycle(moodycamel::ConcurrentQueue<char *> &free_buffers) {
167182
}
168183

169184
VecBufferPool::VecBufferPool(const std::string &filename) {
185+
#if defined(_MSC_VER)
186+
fd_ = _open(filename.c_str(), O_RDONLY | _O_BINARY);
187+
#else
170188
fd_ = open(filename.c_str(), O_RDONLY);
189+
#endif
171190
if (fd_ < 0) {
172191
throw std::runtime_error("Failed to open file: " + filename);
173192
}
193+
#if defined(_MSC_VER)
194+
struct _stat64 st;
195+
if (_fstat64(fd_, &st) < 0) {
196+
_close(fd_);
197+
#else
174198
struct stat st;
175199
if (fstat(fd_, &st) < 0) {
176200
::close(fd_);
201+
#endif
177202
throw std::runtime_error("Failed to stat file: " + filename);
178203
}
179204
file_size_ = st.st_size;
@@ -247,7 +272,11 @@ char *VecBufferPool::acquire_buffer(block_id_t block_id, size_t offset,
247272
}
248273
}
249274

275+
#if defined(_MSC_VER)
276+
ssize_t read_bytes = zvec_pread(fd_, buffer, size, offset);
277+
#else
250278
ssize_t read_bytes = pread(fd_, buffer, size, offset);
279+
#endif
251280
if (read_bytes != static_cast<ssize_t>(size)) {
252281
LOG_ERROR("Buffer pool failed to read file at offset: %zu", offset);
253282
free_buffers_.enqueue(buffer);
@@ -257,7 +286,11 @@ char *VecBufferPool::acquire_buffer(block_id_t block_id, size_t offset,
257286
}
258287

259288
int VecBufferPool::get_meta(size_t offset, size_t length, char *buffer) {
289+
#if defined(_MSC_VER)
290+
ssize_t read_bytes = zvec_pread(fd_, buffer, length, offset);
291+
#else
260292
ssize_t read_bytes = pread(fd_, buffer, length, offset);
293+
#endif
261294
if (read_bytes != static_cast<ssize_t>(length)) {
262295
LOG_ERROR("Buffer pool failed to read file at offset: %zu", offset);
263296
return -1;

src/include/zvec/ailego/buffer/buffer_pool.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <sys/stat.h>
44
#include <fcntl.h>
5-
#include <unistd.h>
65
#include <atomic>
76
#include <cassert>
87
#include <cstdio>
@@ -20,6 +19,11 @@
2019
#include <zvec/ailego/internal/platform.h>
2120
#include "concurrentqueue.h"
2221

22+
#if defined(_MSC_VER)
23+
#include <io.h>
24+
#include <Windows.h>
25+
#endif
26+
2327
namespace zvec {
2428
namespace ailego {
2529

@@ -107,7 +111,11 @@ class VecBufferPool {
107111
char *b = lp_map_.evict_block(i);
108112
if (b) ailego_free(b);
109113
}
114+
#if defined(_MSC_VER)
115+
_close(fd_);
116+
#else
110117
close(fd_);
118+
#endif
111119
}
112120

113121
int init(size_t pool_capacity, size_t block_size, size_t segment_count);

0 commit comments

Comments
 (0)