@@ -114,27 +114,89 @@ int pdc_server_rank_g = 0;
114
114
int pdc_server_size_g = 1 ;
115
115
double total_mem_usage_g = 0.0 ;
116
116
117
+ int
118
+ isDir (const char * fileName )
119
+ {
120
+ struct stat path ;
121
+ stat (fileName , & path );
122
+ return S_ISREG (path .st_mode );
123
+ }
124
+
117
125
static void pdc_ls (FileNameNode * file_name_node , int argc , char * argv []);
118
126
119
127
int
120
128
main (int argc , char * argv [])
121
129
{
122
130
if (argc == 1 ) {
123
- printf ("Expected directory/checkpoint file.\n" );
124
- return 1 ;
131
+ printf ("Usage: ./pdc_ls pdc_checkpoint_directory/file [-n obj_name] [-i obj_id] [-json json_fname] "
132
+ "[-ln (list all names)] [-ls (list all ids)] [-s (summary)]\n" );
133
+ return 0 ;
125
134
}
126
135
else {
127
136
FileNameNode * head = NULL ;
128
137
FileNameNode * cur_node = NULL ;
129
138
DIR * d ;
130
139
struct dirent * dir ;
140
+ struct dirent * direc ;
131
141
d = opendir (argv [1 ]);
142
+ char * full_path ;
132
143
133
144
if (d ) {
134
145
while ((dir = readdir (d )) != NULL ) {
146
+ // if it's directory
147
+ if (!isDir (dir -> d_name )) {
148
+ if (strstr (dir -> d_name , "." )) {
149
+ // ignore parent and current directories
150
+ continue ;
151
+ }
152
+ // appends path together
153
+ char tmp [1024 ];
154
+ sprintf (tmp , "%s/%s" , argv [1 ], dir -> d_name );
155
+ DIR * d1 = opendir (tmp );
156
+ /* printf("%s\n", tmp); */
157
+
158
+ while ((direc = readdir (d1 )) != NULL ) { // go into it and go for checkpoint files again
159
+ if (strstr (direc -> d_name , "metadata_checkpoint." )) {
160
+ // printf("getting checkpoints\n");
161
+ char last = argv [1 ][strlen (argv [1 ]) - 1 ];
162
+ if (last == '/' ) {
163
+ full_path = (char * )malloc (sizeof (char ) *
164
+ (strlen (argv [1 ]) + strlen (direc -> d_name ) + 1 ));
165
+ strcpy (full_path , argv [1 ]);
166
+ strcat (full_path , direc -> d_name );
167
+ strcat (full_path , "/" );
168
+ strcat (full_path , direc -> d_name );
169
+ }
170
+ else {
171
+ full_path = (char * )malloc (sizeof (char ) *
172
+ (strlen (argv [1 ]) + strlen (direc -> d_name ) + 2 ));
173
+ strcpy (full_path , argv [1 ]);
174
+ strcat (full_path , "/" );
175
+ strcat (full_path , dir -> d_name );
176
+ strcat (full_path , "/" );
177
+ strcat (full_path , direc -> d_name );
178
+ }
179
+ if (head == NULL ) {
180
+ FileNameNode * new_node = (FileNameNode * )malloc (sizeof (FileNameNode ));
181
+ new_node -> file_name = full_path ;
182
+ new_node -> next = NULL ;
183
+ head = new_node ;
184
+ cur_node = new_node ;
185
+ }
186
+ else {
187
+ FileNameNode * new_node = (FileNameNode * )malloc (sizeof (FileNameNode ));
188
+ new_node -> file_name = full_path ;
189
+ new_node -> next = NULL ;
190
+ cur_node -> next = new_node ;
191
+ cur_node = new_node ;
192
+ }
193
+ }
194
+ }
195
+ closedir (d1 );
196
+ }
135
197
if (strstr (dir -> d_name , "metadata_checkpoint." )) {
136
- char last = argv [ 1 ][ strlen ( argv [ 1 ]) - 1 ] ;
137
- char * full_path ;
198
+ printf ( "%s\n" , dir -> d_name ) ;
199
+ char last = argv [ 1 ][ strlen ( argv [ 1 ]) - 1 ] ;
138
200
if (last == '/' ) {
139
201
full_path =
140
202
(char * )malloc (sizeof (char ) * (strlen (argv [1 ]) + strlen (dir -> d_name ) + 1 ));
@@ -163,14 +225,15 @@ main(int argc, char *argv[])
163
225
cur_node = new_node ;
164
226
}
165
227
}
166
- }
228
+ } // End if dir = readdir
167
229
closedir (d );
168
- }
230
+ } // Ene if d
169
231
else {
232
+ // Open one checkpoint file
170
233
FILE * file = fopen (argv [1 ], "r" );
171
234
if (file != NULL ) {
172
- FileNameNode * new_node = (FileNameNode * )malloc (sizeof (FileNameNode ));
173
- char * full_path = (char * )malloc (sizeof (char ) * (strlen (argv [1 ]) + 1 ));
235
+ FileNameNode * new_node = (FileNameNode * )malloc (sizeof (FileNameNode ));
236
+ full_path = (char * )malloc (sizeof (char ) * (strlen (argv [1 ]) + 1 ));
174
237
strcpy (full_path , argv [1 ]);
175
238
new_node -> file_name = full_path ;
176
239
new_node -> next = NULL ;
@@ -179,9 +242,10 @@ main(int argc, char *argv[])
179
242
fclose (file );
180
243
}
181
244
}
245
+
182
246
if (head == NULL ) {
183
247
printf ("Unable to open/locate checkpoint file(s).\n" );
184
- return 1 ;
248
+ return - 1 ;
185
249
}
186
250
else {
187
251
pdc_ls (head , argc , argv );
@@ -311,6 +375,7 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
311
375
int list_names = 0 ;
312
376
int list_ids = 0 ;
313
377
int summary = 0 ;
378
+ int print_all = 1 ;
314
379
315
380
int arg_index = 2 ;
316
381
while (arg_index < argc ) {
@@ -332,12 +397,15 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
332
397
}
333
398
else if (strcmp (argv [arg_index ], "-ln" ) == 0 ) {
334
399
list_names = 1 ;
400
+ print_all = 0 ;
335
401
}
336
402
else if (strcmp (argv [arg_index ], "-li" ) == 0 ) {
337
- list_ids = 1 ;
403
+ list_ids = 1 ;
404
+ print_all = 0 ;
338
405
}
339
406
else if (strcmp (argv [arg_index ], "-s" ) == 0 ) {
340
- summary = 1 ;
407
+ summary = 1 ;
408
+ print_all = 0 ;
341
409
}
342
410
arg_index ++ ;
343
411
}
@@ -365,7 +433,7 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
365
433
while (cur_file_node != NULL ) {
366
434
filename = cur_file_node -> file_name ;
367
435
stat (filename , & attr );
368
- printf ("[INFO] File [%s] last modified at: %s\n " , filename , ctime (& attr .st_mtime ));
436
+ printf ("[INFO] File [%s] last modified at: %s" , filename , ctime (& attr .st_mtime ));
369
437
// Start server restart code
370
438
perr_t ret_value = SUCCEED ;
371
439
int n_entry , count , i , j , nobj = 0 , all_nobj = 0 , all_n_region , n_region , n_objs , total_region = 0 ,
@@ -387,19 +455,21 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
387
455
}
388
456
389
457
if (fread (& n_cont , sizeof (int ), 1 , file ) != 1 ) {
390
- printf ("Read failed for n_count \n" );
458
+ printf ("Read failed for cont count \n" );
391
459
}
392
460
all_cont = n_cont ;
393
461
while (n_cont > 0 ) {
394
462
hash_key = (uint32_t * )malloc (sizeof (uint32_t ));
395
463
if (fread (hash_key , sizeof (uint32_t ), 1 , file ) != 1 ) {
396
- printf ("Read failed for hash_key\n" );
464
+ printf ("Read failed for cont hash_key\n" );
465
+ return ;
397
466
}
398
467
399
468
// Reconstruct hash table
400
469
cont_entry = (pdc_cont_hash_table_entry_t * )malloc (sizeof (pdc_cont_hash_table_entry_t ));
401
470
if (fread (cont_entry , sizeof (pdc_cont_hash_table_entry_t ), 1 , file ) != 1 ) {
402
471
printf ("Read failed for cont_entry\n" );
472
+ return ;
403
473
}
404
474
405
475
n_cont -- ;
@@ -410,12 +480,14 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
410
480
411
481
while (n_entry > 0 ) {
412
482
if (fread (& count , sizeof (int ), 1 , file ) != 1 ) {
413
- printf ("Read failed for count\n" );
483
+ printf ("Read failed for obj count\n" );
484
+ return ;
414
485
}
415
486
416
487
hash_key = (uint32_t * )malloc (sizeof (uint32_t ));
417
488
if (fread (hash_key , sizeof (uint32_t ), 1 , file ) != 1 ) {
418
- printf ("Read failed for hash_key\n" );
489
+ printf ("Read failed for obj hash_key\n" );
490
+ return ;
419
491
}
420
492
421
493
// Reconstruct hash table
@@ -481,6 +553,9 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
481
553
if (fread (& kvtag_list -> kvtag -> size , sizeof (uint32_t ), 1 , file ) != 1 ) {
482
554
printf ("Read failed for kvtag_list->kvtag->size\n" );
483
555
}
556
+ if (fread (& kvtag_list -> kvtag -> type , sizeof (int8_t ), 1 , file ) != 1 ) {
557
+ printf ("Read failed for kvtag_list->kvtag->size\n" );
558
+ }
484
559
kvtag_list -> kvtag -> value = malloc (kvtag_list -> kvtag -> size );
485
560
if (fread (kvtag_list -> kvtag -> value , kvtag_list -> kvtag -> size , 1 , file ) != 1 ) {
486
561
printf ("Read failed for kvtag_list->kvtag->value\n" );
@@ -653,11 +728,11 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
653
728
cJSON * start_arr_json = NULL ;
654
729
cJSON * output = cJSON_CreateObject ();
655
730
int prev_cont_id = -1 ;
731
+ char buf [1024 ];
656
732
while (cur_m_node != NULL ) {
657
733
cur_metadata = cur_m_node -> metadata_ptr ;
658
734
if (prev_cont_id != cur_metadata -> cont_id ) {
659
735
cont_id_json = cJSON_CreateArray ();
660
- char buf [20 ];
661
736
sprintf (buf , "cont_id: %d" , cur_metadata -> cont_id );
662
737
cJSON_AddItemToObject (output , buf , cont_id_json );
663
738
}
@@ -678,7 +753,6 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
678
753
}
679
754
}
680
755
681
- char buf [12 ];
682
756
sprintf (buf , "%d" , wanted_id );
683
757
reti = regcomp (& regex , buf , 0 );
684
758
if (reti ) {
@@ -687,7 +761,6 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
687
761
}
688
762
}
689
763
else {
690
- // char buf[12];
691
764
sprintf (buf , "%d" , cur_metadata -> obj_id );
692
765
reti = regexec (& regex , buf , 0 , NULL , 0 );
693
766
if (!reti ) {
@@ -715,8 +788,7 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
715
788
add_obj = matched_name ;
716
789
}
717
790
else if (wanted_id ) {
718
- int matched_id = 0 ;
719
- char buf [12 ];
791
+ int matched_id = 0 ;
720
792
sprintf (buf , "%d" , wanted_id );
721
793
reti = regcomp (& regex , buf , 0 );
722
794
if (reti ) {
@@ -725,7 +797,6 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
725
797
}
726
798
}
727
799
else {
728
- // char buf[12];
729
800
sprintf (buf , "%d" , cur_metadata -> obj_id );
730
801
reti = regexec (& regex , buf , 0 , NULL , 0 );
731
802
if (!reti ) {
@@ -739,7 +810,6 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
739
810
add (obj_names , cur_metadata -> obj_name );
740
811
}
741
812
if (list_ids ) {
742
- char buf [12 ];
743
813
sprintf (buf , "%d" , cur_metadata -> obj_id );
744
814
add (obj_ids , buf );
745
815
}
@@ -768,8 +838,6 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
768
838
cJSON_AddStringToObject (region_info_json , "storage_loc" , cur_region -> storage_location );
769
839
cJSON_AddNumberToObject (region_info_json , "offset" , cur_region -> offset );
770
840
cJSON_AddNumberToObject (region_info_json , "num_dims" , cur_region -> ndim );
771
- // FIXME: statement with no effect. what did we expect to do here?
772
- // dims[cur_region->ndim];
773
841
for (int i = 0 ; i < (cur_metadata -> ndim ); i ++ ) {
774
842
dims [i ] = (cur_region -> start )[i ];
775
843
}
@@ -798,13 +866,13 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
798
866
FILE * fp ;
799
867
if (output_file_name ) {
800
868
fp = fopen (output_file_name , "w" );
869
+ printf ("Output to [%s]\n" , output_file_name );
801
870
}
802
871
else {
803
872
fp = stdout ;
804
873
}
805
874
if (list_names ) {
806
- cJSON * all_names_json =
807
- cJSON_CreateStringArray ((const char * const * )obj_names -> items , obj_names -> length );
875
+ cJSON * all_names_json = cJSON_CreateStringArray ((const char * * )obj_names -> items , obj_names -> length );
808
876
cJSON_AddItemToObject (output , "all_obj_names" , all_names_json );
809
877
}
810
878
if (list_ids ) {
@@ -816,7 +884,6 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
816
884
cJSON_AddItemToObject (output , "all_obj_ids" , all_ids_json );
817
885
}
818
886
if (summary ) {
819
- char buf [100 ];
820
887
sprintf (buf , "pdc_ls found: %d containers, %d objects, %d regions" , all_cont_total , all_nobj_total ,
821
888
all_n_region_total );
822
889
cJSON_AddStringToObject (output , "summary" , buf );
@@ -827,4 +894,6 @@ pdc_ls(FileNameNode *file_name_node, int argc, char *argv[])
827
894
char * json_string = cJSON_Print (output );
828
895
fprintf (fp , json_string );
829
896
fprintf (fp , "\n" );
897
+ if (output_file_name )
898
+ fclose (fp );
830
899
}
0 commit comments