Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
zacw7 committed Oct 29, 2024
1 parent a688ce0 commit 8ee8994
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
52 changes: 50 additions & 2 deletions velox/common/caching/SsdFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ SsdFile::SsdFile(const Config& config)
fs_ = filesystems::getFileSystem(fileName_, nullptr);
filesystems::FileOptions fileOptions;
fileOptions.shouldThrowOnFileAlreadyExists = false;
fileOptions.bufferWrite = false;
fileOptions.bufferWrite = !FLAGS_ssd_odirect;
writeDataFile_ = fs_->openFileForWrite(fileName_, fileOptions);
readDataFile_ = fs_->openFileForRead(fileName_);

Expand Down Expand Up @@ -491,7 +491,55 @@ bool SsdFile::write(
<< "Failed to write to SSD, file name: " << fileName_
<< ", size: " << iovecs.size() << ", offset: " << offset
<< ", error code: " << errno
<< ", error string: " << folly::errnoStr(errno);
<< ", error string: " << folly::errnoStr(errno)
<< ", file size: " << writeDataFile_->size();
// 1. The file descriptor fd is not valid.
// 2. The array of buffers iov is null or has a null pointer in it.
// 3. The number of buffers iovcnt is less than 1 or greater than
// UIO_MAXIOV.
// 4. The offset offset is negative or greater than the size of the file.
auto fd = writeDataFile_->fd();
VELOX_SSD_CACHE_LOG(ERROR) << " fd " << fd;
int flags = fcntl(fd, F_GETFD);
VELOX_SSD_CACHE_LOG(ERROR)
<< "fd flags: " << flags << " err: " << folly::errnoStr(errno);
VELOX_SSD_CACHE_LOG(ERROR) << " iovecs ";
for (const auto& iovec : iovecs) {
VELOX_SSD_CACHE_LOG(ERROR)
<< "iov_base: " << iovec.iov_base << " iov_len " << iovec.iov_len;
ssize_t n = writev(fd, &iovec, 1);
if (n == -1) {
VELOX_SSD_CACHE_LOG(ERROR)
<< "[writev] n:" << n << " -> " << folly::errnoStr(errno);

char str0[] = "hello ";
char str1[] = "world\n";
struct iovec iov[2];
ssize_t bytes_written;

iov[0].iov_base = str0;
iov[0].iov_len = strlen(str0);
iov[1].iov_base = str1;
iov[1].iov_len = strlen(str1);

filesystems::FileOptions fileOptions;
fileOptions.shouldThrowOnFileAlreadyExists = false;
fileOptions.bufferWrite = true;
bytes_written = writev(fd, iov, 2);
VELOX_SSD_CACHE_LOG(ERROR) << "[writev] bytes_written:" << bytes_written
<< " -> " << folly::errnoStr(errno);

auto wsfile = fs_->openFileForWrite("tmp.filex", fileOptions);
bytes_written = writev(wsfile->fd(), iov, 2);
VELOX_SSD_CACHE_LOG(ERROR)
<< "[writev] to tmp wsfile:" << wsfile->fd() << bytes_written
<< bytes_written << " -> " << folly::errnoStr(errno);

exit(1);
}
}
VELOX_SSD_CACHE_LOG(ERROR) << " iovcnt " << iovecs.size();
VELOX_SSD_CACHE_LOG(ERROR) << " offset " << offset;
++stats_.writeSsdErrors;
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions velox/common/file/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ LocalWriteFile::LocalWriteFile(
flags |= O_EXCL;
}
#ifdef linux
LOG(WARNING) << "bufferWrite" << bufferWrite;
if (!bufferWrite) {
LOG(WARNING) << "flags |= O_DIRECT";
flags |= O_DIRECT;
}
#endif // linux
Expand Down
9 changes: 9 additions & 0 deletions velox/common/file/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ class WriteFile {
/// be needed to get the exact size written, and this should be able to be
/// called after the file close.
virtual uint64_t size() const = 0;

virtual int32_t fd() {
VELOX_NYI("{} is not implemented", __FUNCTION__);
}
};

// We currently do a simple implementation for the in-memory files
Expand Down Expand Up @@ -349,6 +353,11 @@ class LocalWriteFile final : public WriteFile {
return size_;
}

int32_t fd() {
return fd_;
}


private:
// File descriptor.
int32_t fd_{-1};
Expand Down

0 comments on commit 8ee8994

Please sign in to comment.