Added boilerplates for index GC

Fixed misspelling: s/indicies/indexes/g
master
Vladimir Stackov 2015-08-06 14:02:55 +03:00
parent e76c0db562
commit 3ff24945a2
7 changed files with 52 additions and 35 deletions

View File

@ -3,17 +3,6 @@
#include "backup_collector.hh"
#include <string>
#include <vector>
#include "bundle.hh"
#include "chunk_index.hh"
#include "backup_restorer.hh"
#include "backup_file.hh"
#include "backup_exchanger.hh"
#include "debug.hh"
using std::string;
void BundleCollector::startIndex( string const & indexFn )

View File

@ -4,18 +4,11 @@
#ifndef BACKUP_COLLECTOR_HH_INCLUDED
#define BACKUP_COLLECTOR_HH_INCLUDED
#include "zbackup_base.hh"
#include "chunk_storage.hh"
#include <string>
#include <vector>
#include <unistd.h>
#include "bundle.hh"
#include "chunk_index.hh"
#include "backup_restorer.hh"
#include "backup_file.hh"
#include "backup_exchanger.hh"
#include "debug.hh"

View File

@ -17,7 +17,7 @@ using std::pair;
enum {
backups,
bundles,
index,
indexes,
Flags
};

View File

@ -119,7 +119,7 @@ void Config::prefillKeywords()
"Valid values:\n"
"backups - exchange backup instructions (files in backups/ directory)\n"
"bundles - exchange bundles with data (files in bunles/ directory)\n"
"index - exchange indicies of chunks (files in index/ directory)\n"
"indexes - exchange indexes of chunks (files in index/ directory)\n"
"No default value, you should specify it explicitly"
},
@ -439,12 +439,13 @@ bool Config::parseOrValidate( const string & option, const OptionType type,
if ( strcmp( optionValue, "bundles" ) == 0 )
runtime.exchange.set( BackupExchanger::bundles );
else
if ( strcmp( optionValue, "index" ) == 0 )
runtime.exchange.set( BackupExchanger::index );
if ( strcmp( optionValue, "indexes" ) == 0 ||
strcmp( optionValue, "index" ) == 0 )
runtime.exchange.set( BackupExchanger::indexes );
else
{
fprintf( stderr, "Invalid exchange value specified: %s\n"
"Must be one of the following: backups, bundles, index.\n",
"Must be one of the following: backups, bundles, indexes.\n",
optionValue );
return false;
}

View File

@ -172,7 +172,8 @@ invalid_option:
" performs import from source to destination storage,\n"
" for export/import storage path must be\n"
" a valid (initialized) storage\n"
" gc <storage path> - performs chunk garbage collection\n"
" gc [chunks|indexes] <storage path> - performs garbage\n"
" collection (default is chunks)\n"
" passwd <storage path> - changes repo info file passphrase\n"
//" info <storage path> - shows repo information\n"
" config [show|edit|set|reset] <storage path> - performs\n"
@ -278,15 +279,43 @@ invalid_option:
else
if ( strcmp( args[ 0 ], "gc" ) == 0 )
{
// Perform the restore
if ( args.size() != 2 )
// Perform the garbage collection
if ( args.size() < 2 || args.size() > 3 )
{
fprintf( stderr, "Usage: %s %s <storage path>\n",
fprintf( stderr, "Usage: %s %s [chunks|indexes] <storage path>\n",
*argv, args[ 0 ] );
return EXIT_FAILURE;
}
ZCollector zc( args[ 1 ], passwords[ 0 ], config );
zc.gc();
int fieldStorage = 1;
int fieldAction = 2;
if ( args.size() == 3 )
{
fieldStorage = 2;
fieldAction = 1;
}
if ( args.size() > 2 && strcmp( args[ fieldAction ], "chunks" ) == 0 )
{
ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ),
passwords[ 0 ], config );
zc.gcChunks();
}
else
if ( args.size() > 2 && strcmp( args[ fieldAction ], "indexes" ) == 0 )
{
ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ),
passwords[ 0 ], config );
fprintf( stderr, "NOT IMPLEMENTED YET!\n" );
zc.gcIndexes();
}
else
{
ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ),
passwords[ 0 ], config );
zc.gcChunks();
}
}
else
if ( strcmp( args[ 0 ], "passwd" ) == 0 )

View File

@ -207,13 +207,13 @@ void ZExchange::exchange()
verbosePrintf( "Bundle exchange completed.\n" );
}
if ( config.runtime.exchange.test( BackupExchanger::index ) )
if ( config.runtime.exchange.test( BackupExchanger::indexes ) )
{
verbosePrintf( "Searching for indicies...\n" );
vector< string > indicies = BackupExchanger::findOrRebuild(
verbosePrintf( "Searching for indexes...\n" );
vector< string > indexes = BackupExchanger::findOrRebuild(
srcZBackupBase.getIndexPath(), dstZBackupBase.getIndexPath() );
for ( std::vector< string >::iterator it = indicies.begin(); it != indicies.end(); ++it )
for ( std::vector< string >::iterator it = indexes.begin(); it != indexes.end(); ++it )
{
verbosePrintf( "Processing index file %s... ", it->c_str() );
string outputFileName ( Dir::addPath( dstZBackupBase.getIndexPath(), *it ) );
@ -307,7 +307,7 @@ ZCollector::ZCollector( string const & storageDir, string const & password,
{
}
void ZCollector::gc()
void ZCollector::gcChunks()
{
ChunkIndex chunkReindex( encryptionkey, tmpMgr, getIndexPath(), true );
@ -366,3 +366,7 @@ void ZCollector::gc()
verbosePrintf( "Garbage collection complete\n" );
}
void ZCollector::gcIndexes()
{
}

View File

@ -55,7 +55,8 @@ public:
ZCollector( std::string const & storageDir, std::string const & password,
Config & configIn );
void gc();
void gcChunks();
void gcIndexes();
};
#endif