Changeset 766:8820bcce0c46


Ignore:
Timestamp:
01/11/12 12:28:48 (4 months ago)
Author:
delmitz@delmitz-PC.office.nchovy.net
Branch:
default
Message:

increase traverse speed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kraken-logstorage/src/main/java/org/krakenapps/logstorage/engine/v2/LogFileReaderV2.java

    r255 r766  
    6767                        pos += 4 + header.logCount * INDEX_ITEM_SIZE; 
    6868                } 
    69                 logger.trace("kraken logstorage: {} has {} blocks, {} logs.", new Object[] { indexPath.getName(), 
    70                                 indexBlockHeaders.size(), logCount }); 
     69                logger.trace("kraken logstorage: {} has {} blocks, {} logs.", new Object[] { indexPath.getName(), indexBlockHeaders.size(), 
     70                                logCount }); 
    7171 
    7272                this.dataFile = new RandomAccessFile(dataPath, "r"); 
     
    126126 
    127127        @Override 
    128         public void traverse(Date from, Date to, int limit, LogRecordCallback callback) throws IOException, 
    129                         InterruptedException { 
     128        public void traverse(Date from, Date to, int limit, LogRecordCallback callback) throws IOException, InterruptedException { 
    130129                int matched = 0; 
    131130 
     131                Long fromTime = (from == null) ? null : from.getTime(); 
     132                Long toTime = (to == null) ? null : to.getTime(); 
    132133                for (int i = dataBlockHeaders.size() - 1; i >= 0; i--) { 
    133134                        DataBlockHeader header = dataBlockHeaders.get(i); 
    134                         if ((from == null || header.endDate >= from.getTime()) && (to == null || header.startDate <= to.getTime())) { 
    135                                 Long f = (from != null) ? from.getTime() : null; 
    136                                 Long t = (to != null) ? to.getTime() : null; 
    137                                 matched += readBlock(i, f, t, limit - matched, callback); 
     135                        if ((fromTime == null || header.endDate >= fromTime) && (toTime == null || header.startDate <= toTime)) { 
     136                                matched += readBlock(i, fromTime, toTime, limit - matched, callback); 
    138137                                if (matched == limit) 
    139138                                        return; 
     
    142141        } 
    143142 
    144         private int readBlock(int blockId, Long from, Long to, int limit, LogRecordCallback callback) throws IOException, 
    145                         InterruptedException { 
     143        private int readBlock(int blockId, Long from, Long to, int limit, LogRecordCallback callback) throws IOException, InterruptedException { 
    146144                IndexBlockHeader header = indexBlockHeaders.get(blockId); 
    147145                List<Integer> offsets = new ArrayList<Integer>(); 
     
    149147 
    150148                indexFile.seek(header.fp + 4); 
     149                ByteBuffer indexBuffer = ByteBuffer.allocate(header.logCount * 4); 
     150                indexFile.read(indexBuffer.array()); 
    151151                for (int i = 0; i < header.logCount; i++) 
    152                         offsets.add(indexFile.readInt()); 
     152                        offsets.add(indexBuffer.getInt()); 
    153153 
    154154                // reverse order 
Note: See TracChangeset for help on using the changeset viewer.