HashDataInc/Gopherwood

bug - file write raise assert exception

chenbaggio opened this issue · 0 comments

  1. test code

#include
#include
#include <fcntl.h>
#include
#include
#include "gopherwood/gopherwood.h"

int main(int agrInt, char **agrStr)
{
for (int i = 0; i < 10; i++) {
testGWWrite("TestReadWriteSeek-ReadEvictBlock");
}

return 0

}

using namespace std;

void testGWWrite(std::string fileName) {
AccessFileType type = randomType;

gopherwoodFS gwFS = gwCreateContext((char *) fileName.c_str());
gwFile file = gwOpenFile(gwFS, (char *) fileName.c_str(), O_CREAT);

int SIZE = 128;
//3. construct the file name
std::stringstream ss;
ss << "/ssdfile/ssdkv/" << fileName;
std::string filePath = ss.str();

//4. read data from file
std::ifstream infile;
infile.open(filePath.c_str());


int totalWriteLength = 0;
char *buf = new char[SIZE];
infile.read(buf, SIZE);
int readLengthIn = infile.gcount();
while (readLengthIn > 0) {
    totalWriteLength += readLengthIn;
    std::cout << "totalWriteLength=" << totalWriteLength << ",readLength="
              << readLengthIn << std::endl;
    std::cout << "buf=" << buf << std::endl;
    //5. write data to the gopherwood
    gwWrite(gwFS, file, buf, readLengthIn);

    buf = new char[SIZE];
    infile.read(buf, SIZE);
    readLengthIn = infile.gcount();
}

gwCloseFile(gwFS, file);

std::cout << "*******END OF WRITE*****, totalWriteLength=" << totalWriteLength << std::endl;

}
2. pre-condition
code version:
branch: master
commit e385461
Author: houliang neuyilan@163.com
Date: Wed Feb 7 16:58:10 2018 +0800

running env:
/ssdfile/ssdkv/TestReadWriteSeek-ReadEvictBlock 4096 bytes
/ssdfile/ssdkv/sharedMemory/smFile 40960 bytes and initalize to total zero

  1. assert exception
    call stack:
    #0 0x00007ffff6c1a1f7 in raise () from /lib64/libc.so.6
    #1 0x00007ffff6c1b8e8 in abort () from /lib64/libc.so.6
    #2 0x00007ffff6c13266 in __assert_fail_base () from /lib64/libc.so.6
    #3 0x00007ffff6c13312 in __assert_fail () from /lib64/libc.so.6
    #4 0x00007ffff7b6f389 in Gopherwood::Internal::FileSystemImpl::acquireNewBlock (this=0x605a70, fileName=0x607368 "TestReadWriteSeek-ReadEvictBlock") at /opt/Gopherwood/src/core/FileSystemImpl.cpp:533
    #5 0x00007ffff7b84692 in Gopherwood::Internal::OutputStreamImpl::writeInternal (this=0x608b10, buf=0x60b900 "", size=128) at /opt/Gopherwood/src/core/OutputStreamImpl.cpp:101
    #6 0x00007ffff7b84413 in Gopherwood::Internal::OutputStreamImpl::write (this=0x608b10, buf=0x60b900 "", size=128) at /opt/Gopherwood/src/core/OutputStreamImpl.cpp:72
    #7 0x00007ffff7b83ae5 in Gopherwood::OutputStream::write (this=0x607330, buf=0x60b900 "", size=128) at /opt/Gopherwood/src/core/OutputStream.cpp:32
    #8 0x00007ffff7b8acc7 in gwWrite (fs=0x6072f0, file=0x607310, buffer=0x60b900, length=128) at /opt/Gopherwood/src/core/gopherwood.cpp:313
    #9 0x0000000000401633 in testGWWrite (fileName="TestReadWriteSeek-ReadEvictBlock") at TestGWAPI.cpp:48
    #10 0x0000000000401c2a in main (agrInt=2, agrStr=0x7fffffffe258) at TestGWAPI.cpp:128