Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/less-TRACEPOINT-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex authored Jul 14, 2020
2 parents 4072dd4 + 1a18682 commit d573d65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
9 changes: 9 additions & 0 deletions libdevcore/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@

#include <skale/buildinfo.h>

#include <thread>

using namespace std;

namespace dev {
char const* Version = skale_get_buildinfo()->project_version;
bytes const NullBytes;
std::string const EmptyString;

void ExitHandler::exitHandler( int s ) {
m_signal = s;
s_shouldExit = true;
// HACK wait for loop in main to send exit call to consensus et al.
std::this_thread::sleep_for( chrono::milliseconds( 2000 ) );
}

void InvariantChecker::checkInvariants(
HasInvariants const* _this, char const* _fn, char const* _file, int _line, bool _pre ) {
if ( !_this->invariants() ) {
Expand Down
5 changes: 1 addition & 4 deletions libdevcore/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,7 @@ int64_t utcTime();

class ExitHandler {
public:
static void exitHandler( int s ) {
m_signal = s;
s_shouldExit = true;
}
static void exitHandler( int s );
static bool shouldExit() { return s_shouldExit; }
static int getSignal() { return m_signal; }

Expand Down
34 changes: 20 additions & 14 deletions libskale/SnapshotManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,16 @@ void SnapshotManager::removeSnapshot( unsigned _blockNumber ) {

// exeptions: filesystem
void SnapshotManager::leaveNLastSnapshots( unsigned n ) {
multimap< time_t, fs::path, std::greater< time_t > > time_map;
map< int, fs::path, std::greater< int > > numbers;
for ( auto& f : fs::directory_iterator( snapshots_dir ) ) {
// HACK We exclude 0 snapshot forcefully
if ( fs::basename( f ) != "0" )
time_map.insert( make_pair( fs::last_write_time( f ), f ) );
numbers.insert( make_pair( std::stoi( fs::basename( f ) ), f ) );
} // for

// delete all efter n first
// delete all after n first
unsigned i = 1;
for ( const auto& p : time_map ) {
for ( const auto& p : numbers ) {
if ( i++ > n ) {
const fs::path& path = p.second;
for ( const string& v : this->volumes ) {
Expand All @@ -273,37 +273,40 @@ void SnapshotManager::leaveNLastSnapshots( unsigned n ) {
}

std::pair< int, int > SnapshotManager::getLatestSnasphot() const {
multimap< time_t, fs::path, std::greater< time_t > > time_map;
map< int, fs::path, std::greater< int > > numbers;
for ( auto& f : fs::directory_iterator( snapshots_dir ) ) {
// HACK We exclude 0 snapshot forcefully
if ( fs::basename( f ) != "0" )
time_map.insert( make_pair( fs::last_write_time( f ), f ) );
}
if ( time_map.empty() ) {
numbers.insert( make_pair( std::stoi( fs::basename( f ) ), f ) );
} // for

if ( numbers.empty() ) {
return std::make_pair( 0, 0 );
}
auto it = time_map.rbegin();

auto it = numbers.rbegin();
int fst = std::stoi( fs::basename( ( *it++ ).second ) );

int snd;
if ( time_map.size() > 1 ) {
if ( numbers.size() > 1 ) {
snd = 0;
} else {
snd = std::stoi( fs::basename( ( *it ).second ) );
}

return std::make_pair( fst, snd );
}

// exeptions: filesystem
void SnapshotManager::leaveNLastDiffs( unsigned n ) {
multimap< time_t, fs::path, std::greater< time_t > > time_map;
map< int, fs::path, std::greater< int > > numbers;
for ( auto& f : fs::directory_iterator( diffs_dir ) ) {
time_map.insert( make_pair( fs::last_write_time( f ), f ) );
numbers.insert( make_pair( std::stoi( fs::basename( f ) ), f ) );
} // for

// delete all after n first
unsigned i = 1;
for ( const auto& p : time_map ) {
for ( const auto& p : numbers ) {
if ( i++ > n ) {
const fs::path& path = p.second;
fs::remove( path );
Expand Down Expand Up @@ -446,7 +449,10 @@ void SnapshotManager::proceedFileSystemDirectory( const boost::filesystem::path&
} else {
if ( !is_checking ) {
if ( !boost::filesystem::exists( fileHashPathStr ) ) {
throw SnapshotManager::CannotRead( fileHashPathStr );
// hash file hasn't been computed
std::ofstream hash_file( fileHashPathStr );
dev::h256 hash = dev::sha256( it->path().string() );
hash_file << hash;
}
std::ifstream hash_file( fileHashPathStr );
dev::h256 hash;
Expand Down

0 comments on commit d573d65

Please sign in to comment.