some debugging. Not finished ;-)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-SparseFileStorage@6090 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-01-24 21:46:44 +00:00
parent 30a3fe7b06
commit 24071ac137
5 changed files with 50 additions and 7 deletions

View File

@ -613,8 +613,8 @@ void ftFileCreator::forceCheck()
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
std::cerr << "WARNING: forceCheck() for mapped files is not yet implemented." << std::endl;
return ;
// std::cerr << "WARNING: forceCheck() for mapped files is not yet implemented." << std::endl;
// return ;
forceCheckPartialFile() ; // calls ftFileMapper, to ask for re-hashing the partial file
chunkMap.forceCheck(); // sets all chunk to checking mode.

View File

@ -21,6 +21,10 @@ ftFileMapper::ftFileMapper(uint64_t file_size,uint32_t chunk_size)
_mapped_chunks.clear() ;
_mapped_chunks.resize(nb_chunks,-1) ;
_data_chunk_ids.clear() ;
#ifdef DEBUG_FILEMAPPER
consistencyTest();
#endif
}
bool ftFileMapper::computeStorageOffset(uint64_t offset,uint64_t& storage_offset) const
@ -162,7 +166,11 @@ bool ftFileMapper::storeData(void *data, uint32_t data_size, uint64_t offset,FIL
_data_chunk_ids[empty_chunk] = cid ;
}
real_offset = _mapped_chunks[cid]*_chunk_size + (offset % (uint64_t)_chunk_size) ;
#ifdef DEBUG_FILEMAPPER
consistencyTest();
#endif
real_offset = _mapped_chunks[cid]*(uint64_t)_chunk_size + (offset % (uint64_t)_chunk_size) ;
}
#ifdef DEBUG_FILEMAPPER
std::cerr << "(DD) real offset = " << real_offset << ", data size=" << data_size << std::endl;
@ -203,9 +211,14 @@ uint32_t ftFileMapper::allocateNewEmptyChunk(FILE *fd_out)
std::cerr << "(DD) first free chunk " << first_free_chunk << " is actually mapped to " << old_chunk << ". Moving it." << std::endl;
#endif
moveChunk(_mapped_chunks[first_free_chunk],first_free_chunk,fd_out) ;
moveChunk(old_chunk,first_free_chunk,fd_out) ;
_mapped_chunks[first_free_chunk] = first_free_chunk ;
// After that, the consistency is broken, because
// _data_chunk_ids[old_chunk] = _data_chunk_ids[first_free_chunk] = first_free_chunk
// However, we cannot give a sensible value to _data_chunk_ids[old_chunk] because it's going to
// be attributed by the client.
#ifdef DEBUG_FILEMAPPER
std::cerr << "(DD) Returning " << old_chunk << std::endl;
#endif
@ -294,6 +307,10 @@ void ftFileMapper::initMappedChunks(uint64_t file_size,const CompressedChunkMap&
std::cerr << "(DD) ftFileMapper::initMappedChunks(): printing: " << std::endl;
print() ;
#ifdef DEBUG_FILEMAPPER
consistencyTest();
#endif
}
bool ftFileMapper::moveChunk(uint32_t to_move, uint32_t new_place,FILE *fd_out)
@ -308,7 +325,7 @@ bool ftFileMapper::moveChunk(uint32_t to_move, uint32_t new_place,FILE *fd_out)
#endif
uint32_t new_place_size = (new_place == _mapped_chunks.size()-1)?(_file_size - (_mapped_chunks.size()-1)*_chunk_size) : _chunk_size ;
uint32_t to_move_size = (new_place == _mapped_chunks.size()-1)?(_file_size - (_mapped_chunks.size()-1)*_chunk_size) : _chunk_size ;
uint32_t to_move_size = ( to_move == _mapped_chunks.size()-1)?(_file_size - (_mapped_chunks.size()-1)*_chunk_size) : _chunk_size ;
uint32_t size = std::min(new_place_size,to_move_size) ;
void *buff = malloc(size) ;
@ -318,7 +335,7 @@ bool ftFileMapper::moveChunk(uint32_t to_move, uint32_t new_place,FILE *fd_out)
std::cerr << "(EE) ftFileMapper::moveChunk(): cannot open temporary buffer. Out of memory??" << std::endl;
return false ;
}
if(fseeko64(fd_out, to_move*_chunk_size, SEEK_SET) != 0)
if(fseeko64(fd_out, to_move*(uint64_t)_chunk_size, SEEK_SET) != 0)
{
std::cerr << "(EE) ftFileMapper::moveChunk(): cannot fseek file at position " << to_move*_chunk_size << std::endl;
return false ;
@ -335,7 +352,7 @@ bool ftFileMapper::moveChunk(uint32_t to_move, uint32_t new_place,FILE *fd_out)
return false ;
}
if(fseeko64(fd_out, new_place*_chunk_size, SEEK_SET)!= 0)
if(fseeko64(fd_out, new_place*(uint64_t)_chunk_size, SEEK_SET)!= 0)
{
std::cerr << "(EE) ftFileMapper::moveChunk(): cannot fseek file at position " << new_place*_chunk_size << std::endl;
return false ;
@ -368,4 +385,23 @@ void ftFileMapper::print() const
}
bool ftFileMapper::consistencyTest() const
{
for(uint32_t i=0;i<_data_chunk_ids.size();++i)
if(!(_mapped_chunks[_data_chunk_ids[i]] == i))
{
std::cerr << "(EE) Consistency error in file mapper: _mapped_chunks[_data_chunk_ids[i]] != i, for i=" << i << std::endl;
print() ;
assert(false) ;
}
for(uint32_t i=0;i<_mapped_chunks.size();++i)
if(!( (_mapped_chunks[i] == -1) || (_mapped_chunks[i] < _data_chunk_ids.size() && _data_chunk_ids[_mapped_chunks[i]] == i)))
{
std::cerr << "(EE) Consistency error in file mapper: _mapped_chunks[i] != -1, and _mapped_chunks[i]=" << _mapped_chunks[i] << ". _data_chunk_ids.size()=" << _data_chunk_ids.size() << ", and _data_chunk_ids[_mapped_chunks[i]] == " << _data_chunk_ids[_mapped_chunks[i]] << ", for i=" << i << std::endl;
print() ;
assert(false) ;
}
return true ;
}

View File

@ -86,6 +86,7 @@ class ftFileMapper
// debug
void print() const ;
bool consistencyTest() const ;
virtual void forceCheckPartialFile() {}
private:

View File

@ -26,6 +26,7 @@
/******
* #define FT_DEBUG 1
*****/
#define FT_DEBUG 1
#define USE_NEW_CHUNK_CHECKING_CODE
@ -618,6 +619,10 @@ bool ftTransferModule::checkFile()
#endif
return true ;
}
#ifdef FT_DEBUG
else
std::cerr << "ftTransferModule::checkFile(): hash finished. File verification failed. Computed hash: " << check_hash << ", expected: " << mHash << std::endl ;
#endif
}

View File

@ -78,6 +78,7 @@ int main(int argc,char *argv[])
CHECK(fmapper.storeData( (unsigned char *)membuf+chunk.offset,chunk.size,chunk.offset,fout) ) ;
chunk_map.dataReceived(chunk.id) ;
fmapper.consistencyTest() ;
fmapper.print() ;
delete chunk.ref_cnt ;