Ignore:
Timestamp:
2017-01-23T20:37:32+13:00 (7 years ago)
Author:
davidb
Message:

Too expensive to hold pairtree filename in hashmap, so change to computing on-the-fly from 'id'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/hathitrust/wcsa/vol-checker/src/org/hathitrust/extractedfeatures/VolumeCheck.java

    r31334 r31335  
    2727
    2828    protected static int HASHMAP_INIT_SIZE = 13800000;
    29     //protected static String DATA_DIR="D:/cygwin64/home/davidb/research/code-managed/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest";
    30     protected static HashMap<String,String> id_check_ = null;
     29    protected static HashMap<String,Boolean> id_check_ = null;
    3130   
    32    
    3331    public VolumeCheck() {
    3432       
    3533    }
    3634
    37     protected static final String opt_file_ext = ".json.bz2";
    38    
    39     protected String full_filename_to_tail(String full_filename)
     35    protected static final String file_ext = ".json.bz2";
     36   
     37    protected static String full_filename_to_tail(String full_filename)
    4038    {
    4139        String filename_tail = full_filename.substring(full_filename.lastIndexOf("/")+1);
     
    4341    }
    4442   
    45     protected String filename_tail_to_id(String filename_tail)
     43    protected static String filename_tail_to_id(String filename_tail)
    4644    {
    4745        String id = null;
    48         if (filename_tail.endsWith(opt_file_ext)) {
    49             id = filename_tail.substring(0,filename_tail.lastIndexOf(opt_file_ext));
     46        if (filename_tail.endsWith(file_ext)) {
     47            id = filename_tail.substring(0,filename_tail.lastIndexOf(file_ext));
    5048        }
    5149        else {
     
    5654       
    5755        return id;
     56    }
     57   
     58    protected static String id_to_pairtree_filename(String id) {
     59        // Example :-
     60        //   id: miun.adx6300.0001.001
     61        //   pairtree filename: miun/pairtree_root/ad/x6/30/0,/00/01/,0/01/adx6300,0001,001/miun.adx6300,0001,001.json.bz2
     62       
     63        // 1. Map 'difficult' chars:
     64        //   . => ,
     65        //   : => +
     66        //   / => =
     67       
     68        // 2. Process resulting string:
     69        //   split on first dot
     70        //   add "pairtree_root"
     71        //   then split everything else 2 chars at a time
     72       
     73        // 3. Finally add in the (safely transformed) id:
     74        //   append directory that is 'id'
     75        //   further append 'id'.json.bz
     76       
     77       
     78        String id_safe = id.replaceAll("\\.", ",").replaceAll(":", "+").replaceAll("/", "=");
     79       
     80        int id_dot_pos = id_safe.indexOf(".");
     81        String id_prefix = id_safe.substring(0,id_dot_pos);
     82        String id_tail = id_safe.substring(id_dot_pos+1);
     83       
     84        String [] pairs = id_tail.split("(?<=\\G..)");
     85        String joined_pairs = String.join("/", pairs);
     86
     87        String main_dir = id_prefix + "/pairtree_root/" + joined_pairs;
     88        String filename = main_dir + "/" + id_safe + "/" + id_safe + file_ext;
     89       
     90        return filename;
    5891    }
    5992   
     
    6295        long line_num = 1;
    6396        String line;
    64        
    65        
    6697
    6798        try {
     
    74105                String id = filename_tail_to_id(json_filename_tail);
    75106               
    76                 id_check_.put(id, full_json_filename);
    77 
    78                
     107                id_check_.put(id, true);
     108
    79109                if ((line_num % 100000) == 0) {
    80110                    //System.err.println("sample id = " + id);
     
    99129       
    100130        if (id_check_ == null) {
    101             id_check_ = new HashMap<String,String>(HASHMAP_INIT_SIZE);
     131            id_check_ = new HashMap<String,Boolean>(HASHMAP_INIT_SIZE);
    102132           
    103133            String htrc_list_file = "htrc-ef-all-files.txt";
     
    185215                String id = ids[i];
    186216               
    187                 String full_json_filename = id_check_.get(id);
    188                 boolean status = (full_json_filename != null);
     217                boolean exists = id_check_.get(id);
    189218               
    190219                if (i>0) {
    191220                    pw.append(",");
    192221                }
    193                 pw.append("\"" + id + "\":" + status );
     222                pw.append("\"" + id + "\":" + exists );
    194223            }
    195224            pw.append("}");
     
    200229           
    201230            String id = cgi_id;
    202             String full_json_filename = id_check_.get(id);
    203             boolean status = (full_json_filename != null);
    204             pw.append("{'" + id + "':" + status + "}");
     231            boolean exists = id_check_.get(id);
     232            pw.append("{'" + id + "':" + exists + "}");
    205233        }
    206234        else if (cgi_download_id != null) {
    207235            String download_id = cgi_download_id;
    208             String full_json_filename = id_check_.get(download_id);
    209             boolean exists = (full_json_filename != null);
     236            boolean exists = id_check_.get(download_id);
    210237            if (!exists) {
    211238                // Error
     
    214241            else {
    215242                // rsync -av data.analytics.hathitrust.org::features/{PATH-TO-FILE} .
    216            
     243                String full_json_filename = id_to_pairtree_filename(download_id);
     244               
    217245                doRsyncDownload(full_json_filename);
    218246   
Note: See TracChangeset for help on using the changeset viewer.