Clean up compaction code.

This commit is contained in:
Jonathan Moore Liles 2008-04-23 19:33:44 -05:00
parent 2e7fab494a
commit 05ebbc073b
2 changed files with 11 additions and 17 deletions

View File

@ -327,13 +327,13 @@ Loggable::undo ( void )
} }
/** write a snapshot of the state of all loggable objects, sufficient /** write a snapshot of the state of all loggable objects, sufficient
* for later reconstruction, to /file/ */ * for later reconstruction, to /fp/ */
bool bool
Loggable::snapshot( const char *file ) Loggable::snapshot( FILE *fp )
{ {
FILE *ofp = _fp; FILE *ofp = _fp;
if ( ! ( _fp = fopen( file, "w" ) ) ) if ( ! ( _fp = fp ) )
{ {
_fp = ofp; _fp = ofp;
return false; return false;
@ -345,8 +345,6 @@ Loggable::snapshot( const char *file )
_loggables[ i ]->log_create(); _loggables[ i ]->log_create();
} }
fclose( _fp );
_fp = ofp; _fp = ofp;
return true; return true;
@ -355,19 +353,14 @@ Loggable::snapshot( const char *file )
void void
Loggable::compact ( void ) Loggable::compact ( void )
{ {
fclose( _fp );
_fp = NULL;
/* FIXME: don't use name here */ fseek( _fp, 0, SEEK_SET );
snapshot( "history" ); ftruncate( fileno( _fp ), 0 );
if ( ! ( _fp = fopen( "history", "a+" ) ) ) snapshot( _fp );
{
printf( "Could not open log file for writing!" ); _undo_index = 0;
// return false;
} }
}
void void

View File

@ -68,6 +68,7 @@ class Loggable
static queue <char *> _transaction; static queue <char *> _transaction;
private: private:
int _id; int _id;
char **_old_state; char **_old_state;
@ -88,13 +89,13 @@ private:
log( "\t" ); log( "\t" );
} }
static bool snapshot( FILE * fp );
public: public:
static bool open ( const char *filename ); static bool open ( const char *filename );
static void undo ( void ); static void undo ( void );
static int undo_index ( void ) { return _undo_index; } static int undo_index ( void ) { return _undo_index; }
static bool snapshot( const char *file );
static void compact ( void ); static void compact ( void );
static static