Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
zacw7 committed Oct 28, 2024
1 parent a688ce0 commit ad95226
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
53 changes: 52 additions & 1 deletion velox/common/caching/SsdFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,58 @@ 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_;
// 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);

ssize_t bytes_written;
char buf0[] = "short string\n";
char buf1[] = "This is a longer string\n";
char buf2[] = "This is the longest string in this example\n";
struct iovec iov[3];
iov[0].iov_base = buf0;
iov[0].iov_len = strlen(buf0);
iov[1].iov_base = buf1;
iov[1].iov_len = strlen(buf1);
iov[2].iov_base = buf2;
iov[2].iov_len = strlen(buf2);
int iovcnt = sizeof(iov) / sizeof(struct iovec);

bytes_written = writev(fd, iov, iovcnt);
VELOX_SSD_CACHE_LOG(ERROR) << "[writev] bytes_written:" << bytes_written
<< " -> " << folly::errnoStr(errno);

filesystems::FileOptions fileOptions;
fileOptions.shouldThrowOnFileAlreadyExists = false;
fileOptions.bufferWrite = false;
auto wfile = fs_->openFileForWrite("tmp.file", fileOptions);
bytes_written = writev(wfile->fd(), iov, iovcnt);
VELOX_SSD_CACHE_LOG(ERROR)
<< "[writev]to tmp file:" << wfile->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
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 ad95226

Please sign in to comment.