1 /*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002, 2014 Oracle and/or its affiliates. All rights reserved. 5 * 6 */ 7 8 package com.sleepycat.je.cleaner; 9 10 import com.sleepycat.bind.tuple.TupleInput; 11 import com.sleepycat.bind.tuple.TupleOutput; 12 import com.sleepycat.je.dbi.DatabaseImpl; 13 import com.sleepycat.je.dbi.MemoryBudget; 14 import com.sleepycat.je.log.LogEntryType; 15 import com.sleepycat.je.utilint.DbLsn; 16 17 /** 18 * A sequence of obsolete info. 19 * 20 * To save memory, a TupleOutput is used to contain a sequence of {LSN-file, 21 * LSN-offset, isLN, size} tuples. Packed integers are used and memory is saved 22 * by not using an Object for each tuple, as would be needed in a Java 23 * collection. 24 * 25 * An OffsetList was not used because it does not use packed integers. 26 * PackedOffsets was not used because it depends on offsets being sorted in 27 * ascending order. 28 */ 29 public class PackedObsoleteInfo extends TupleOutput { 30 PackedObsoleteInfo()31 public PackedObsoleteInfo() { 32 } 33 getMemorySize()34 public int getMemorySize() { 35 return MemoryBudget.tupleOutputSize(this); 36 } 37 copyObsoleteInfo(final PackedObsoleteInfo other)38 public void copyObsoleteInfo(final PackedObsoleteInfo other) { 39 writeFast(other.getBufferBytes(), 40 other.getBufferOffset(), 41 other.getBufferLength()); 42 } 43 addObsoleteInfo( final long obsoleteLsn, final boolean isObsoleteLN, final int obsoleteSize)44 public void addObsoleteInfo( 45 final long obsoleteLsn, 46 final boolean isObsoleteLN, 47 final int obsoleteSize) { 48 49 writePackedLong(DbLsn.getFileNumber(obsoleteLsn)); 50 writePackedLong(DbLsn.getFileOffset(obsoleteLsn)); 51 writeBoolean(isObsoleteLN); 52 writePackedInt(obsoleteSize); 53 } 54 countObsoleteInfo( final UtilizationTracker tracker, final DatabaseImpl nodeDb)55 public void countObsoleteInfo( 56 final UtilizationTracker tracker, 57 final DatabaseImpl nodeDb) { 58 59 final TupleInput in = new TupleInput(this); 60 61 while (in.available() > 0) { 62 final long fileNumber = in.readPackedLong(); 63 long fileOffset = in.readPackedLong(); 64 final boolean isObsoleteLN = in.readBoolean(); 65 final int obsoleteSize = in.readPackedInt(); 66 67 tracker.countObsoleteNode( 68 DbLsn.makeLsn(fileNumber, fileOffset), 69 (isObsoleteLN ? 70 LogEntryType.LOG_INS_LN /* Any LN type will do */ : 71 LogEntryType.LOG_IN), 72 obsoleteSize, nodeDb); 73 } 74 } 75 } 76