00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "VestaLog.H"
00024 #include <stdlib.h>
00025
00026 using std::cin;
00027 using std::cout;
00028 using std::cerr;
00029 using std::endl;
00030 using std::fstream;
00031
00032 VestaLog VRLog;
00033
00034 int main()
00035 {
00036 int cknum, ckpkeep, logkeep, readonly, lock, bakckp;
00037 char typein[500];
00038 char junk;
00039 int done;
00040
00041 initial:
00042 cout << "recover from checkpoint # (-1 for last): ";
00043 cin >> cknum;
00044 cin.get(junk);
00045 cout << "readonly (0/1)? ";
00046 cin >> readonly;
00047 cin.get(junk);
00048 cout << "lock (0/1)? ";
00049 cin >> lock;
00050 cin.get(junk);
00051 cout << "backup directory (default none): ";
00052 cin.get(typein, sizeof(typein));
00053 cin.get(junk);
00054 if (typein[0]) {
00055 cout << "backup checkpoint (0/1)? ";
00056 cin >> bakckp;
00057 cin.get(junk);
00058 } else {
00059 bakckp = 0;
00060 }
00061 try {
00062 VRLog.open(".", cknum, readonly, lock,
00063 (typein[0] ? typein : NULL), bakckp);
00064 } catch (VestaLog::Error err) {
00065 cerr << "** error on open **: " << err.msg << endl;
00066 exit(1);
00067 }
00068 fstream *ckpt;
00069 try {
00070 ckpt = VRLog.openCheckpoint();
00071 } catch (VestaLog::Error err) {
00072 cerr << "** error on openCheckpoint **: " << err.msg << endl;
00073 exit(1);
00074 }
00075 if (ckpt == NULL) {
00076 cout << "No checkpoint file\n";
00077 } else {
00078 char c;
00079 cout << "-------checkpoint file-------\n";
00080 while (ckpt->get(c)) cout.put(c);
00081 ckpt->close();
00082 cout << "\n";
00083 }
00084
00085 cout << "-------recovered log-------\n";
00086 for (;;) {
00087 char c;
00088
00089 try {
00090 VRLog.get(c);
00091 cout.put(c);
00092 } catch (VestaLog::Error err) {
00093 cerr << "** error on get **: " << err.msg << endl;
00094 exit(1);
00095 } catch (VestaLog::Eof) {
00096 try {
00097 if (!VRLog.nextLog()) break;
00098 } catch (VestaLog::Error err) {
00099 cerr << "** error on nextLog **: " << err.msg << endl;
00100 exit(1);
00101 }
00102 }
00103 }
00104 cout << "\n-----------------------------\n";
00105
00106 for (;;) {
00107 cout << "(l)og data, close and (r)estart, cl(o)se and quit, (p)rune, (c)heckpoint resume, (q)uit: ";
00108 cin.get(typein, sizeof(typein));
00109 cin.get(junk);
00110 switch (typein[0]) {
00111 case 'l':
00112 try {
00113 VRLog.loggingBegin();
00114 } catch (VestaLog::Error err) {
00115 cerr << "** error on loggingBegin **: " << err.msg << endl;
00116 exit(1);
00117 }
00118 break;
00119 case 'r':
00120 VRLog.close();
00121 goto initial;
00122 case 'o':
00123 VRLog.close();
00124 exit(0);
00125 break;
00126 case 'p':
00127 cout << "ckpkeep: ";
00128 cin >> ckpkeep;
00129 cin.get(junk);
00130 cout << "logkeep (0=false, 1=true): ";
00131 cin >> logkeep;
00132 cin.get(junk);
00133 VRLog.prune(ckpkeep, logkeep);
00134 continue;
00135 case 'c':
00136 {
00137 fstream *nckpt;
00138 try {
00139 nckpt = VRLog.checkpointResume();
00140 } catch (VestaLog::Error err) {
00141 cerr << "** error on checkpointResume **: " <<
00142 err.msg << endl;
00143 exit(1);
00144 }
00145 if (nckpt == NULL) {
00146 cout << "No checkpoint in progress" << endl;
00147 } else {
00148 cout << "checkpoint data: ";
00149 cin.get(typein, sizeof(typein));
00150 cin.get(junk);
00151 *nckpt << typein;
00152 nckpt->close();
00153 }
00154 }
00155 continue;
00156 case 'q':
00157 exit(0);
00158 break;
00159 default:
00160 continue;
00161 }
00162 break;
00163 }
00164
00165
00166 ready:
00167 for (;;) {
00168 cout << "(s)tart record, chec(k)point, checkpoint (e)nd, checkpoint (a)bort, (p)rune, cl(o)se and quit, (q)uit: ";
00169 cin.get(typein, sizeof(typein));
00170 cin.get(junk);
00171 switch (typein[0]) {
00172 case 's':
00173 VRLog.start();
00174 break;
00175 case 'k':
00176 {
00177 fstream *nckpt;
00178 try {
00179 nckpt = VRLog.checkpointBegin();
00180 } catch (VestaLog::Error err) {
00181 cerr << "** error on checkpointBegin **: " <<
00182 err.msg << endl;
00183 exit(1);
00184 }
00185 cout << "checkpoint data: ";
00186 cin.get(typein, sizeof(typein));
00187 cin.get(junk);
00188 *nckpt << typein;
00189 nckpt->close();
00190 }
00191 continue;
00192 case 'e':
00193 try {
00194 VRLog.checkpointEnd();
00195 } catch (VestaLog::Error err) {
00196 cerr << "** error on checkpointEnd **: " <<
00197 err.msg << endl;
00198 exit(1);
00199 }
00200 continue;
00201 case 'a':
00202 try {
00203 VRLog.checkpointAbort();
00204 } catch (VestaLog::Error err) {
00205 cerr << "** error on checkpointAbort **: " <<
00206 err.msg << endl;
00207 exit(1);
00208 }
00209 continue;
00210 case 'o':
00211 VRLog.close();
00212 exit(0);
00213 break;
00214 case 'p':
00215 cout << "ckpkeep: ";
00216 cin >> ckpkeep;
00217 cin.get(junk);
00218 cout << "logkeep (0=false, 1=true): ";
00219 cin >> logkeep;
00220 cin.get(junk);
00221 VRLog.prune(ckpkeep, logkeep);
00222 continue;
00223 case 'q':
00224 exit(0);
00225 break;
00226 default:
00227 continue;
00228 }
00229 break;
00230 }
00231
00232 for (;;) {
00233 cout << "(p)ut data, (c)ommit, (a)bort, cl(o)se and quit, (q)uit: ";
00234 cin.get(typein, sizeof(typein));
00235 cin.get(junk);
00236 switch (typein[0]) {
00237 case 'p':
00238 cout << "log data: ";
00239 cin.get(typein, sizeof(typein));
00240 cin.get(junk);
00241 try {
00242 VRLog.put(typein);
00243 } catch (VestaLog::Error err) {
00244 cerr << "** error on put **: " << err.msg << endl;
00245 exit(1);
00246 }
00247 break;
00248 case 'c':
00249 try {
00250 VRLog.commit();
00251 } catch (VestaLog::Error err) {
00252 cerr << "** error on commit **: " << err.msg << endl;
00253 exit(1);
00254 }
00255 goto ready;
00256 case 'a':
00257 try {
00258 VRLog.abort();
00259 } catch (VestaLog::Error err) {
00260 cerr << "** error on abort **: " << err.msg << endl;
00261 exit(1);
00262 }
00263 goto ready;
00264 case 'o':
00265 VRLog.close();
00266 exit(0);
00267 break;
00268 case 'q':
00269 exit(0);
00270 break;
00271 }
00272 }
00273
00274 return 0;
00275 }