/** Writes the debug dump of the table into logs. Not thread-safe. */
 public void debugDumpTable() {
   StringBuilder dump = new StringBuilder(keysAssigned + " keys\n");
   TreeMap<Long, Integer> byteIntervals = new TreeMap<Long, Integer>();
   int examined = 0;
   for (int slot = 0; slot < refs.length; ++slot) {
     long ref = refs[slot];
     if (ref == 0) {
       continue;
     }
     ++examined;
     long recOffset = getFirstRecordLengthsOffset(ref, null);
     long tailOffset = Ref.getOffset(ref);
     writeBuffers.setReadPoint(recOffset);
     int valueLength = (int) writeBuffers.readVLong(), keyLength = (int) writeBuffers.readVLong();
     long ptrOffset = writeBuffers.getReadPoint();
     if (Ref.hasList(ref)) {
       byteIntervals.put(recOffset, (int) (ptrOffset + 5 - recOffset));
     }
     long keyOffset = tailOffset - valueLength - keyLength;
     byte[] key = new byte[keyLength];
     WriteBuffers.ByteSegmentRef fakeRef = new WriteBuffers.ByteSegmentRef(keyOffset, keyLength);
     byteIntervals.put(keyOffset - 4, keyLength + 4);
     writeBuffers.populateValue(fakeRef);
     System.arraycopy(fakeRef.getBytes(), (int) fakeRef.getOffset(), key, 0, keyLength);
     dump.append(Utils.toStringBinary(key, 0, key.length))
         .append(" ref [")
         .append(dumpRef(ref))
         .append("]: ");
     Result hashMapResult = new Result();
     getValueResult(key, 0, key.length, hashMapResult);
     List<WriteBuffers.ByteSegmentRef> results = new ArrayList<WriteBuffers.ByteSegmentRef>();
     WriteBuffers.ByteSegmentRef byteSegmentRef = hashMapResult.first();
     while (byteSegmentRef != null) {
       results.add(hashMapResult.byteSegmentRef);
       byteSegmentRef = hashMapResult.next();
     }
     dump.append(results.size()).append(" rows\n");
     for (int i = 0; i < results.size(); ++i) {
       WriteBuffers.ByteSegmentRef segment = results.get(i);
       byteIntervals.put(
           segment.getOffset(),
           segment.getLength() + ((i == 0) ? 1 : 0)); // state byte in the first record
     }
   }
   if (examined != keysAssigned) {
     dump.append("Found " + examined + " keys!\n");
   }
   // Report suspicious gaps in writeBuffers
   long currentOffset = 0;
   for (Map.Entry<Long, Integer> e : byteIntervals.entrySet()) {
     long start = e.getKey(), len = e.getValue();
     if (start - currentOffset > 4) {
       dump.append("Gap! [" + currentOffset + ", " + start + ")\n");
     }
     currentOffset = start + len;
   }
   LOG.info("Hashtable dump:\n " + dump.toString());
 }
예제 #2
0
 private List<Object> unpack(WriteBuffers.ByteSegmentRef ref) throws HiveException {
   if (ref.getLength() == 0) {
     return EMPTY_LIST; // shortcut, 0 length means no fields
   }
   uselessIndirection.setData(ref.getBytes());
   valueStruct.init(uselessIndirection, (int) ref.getOffset(), ref.getLength());
   List<Object> result;
   if (!needsComplexObjectFixup) {
     // Good performance for common case where small table has no complex objects.
     result = valueStruct.getFieldsAsList();
   } else {
     // Convert the complex LazyBinary objects to standard (Java) objects so downstream
     // operators like FileSinkOperator can serialize complex objects in the form they expect
     // (i.e. Java objects).
     result = getComplexFieldsAsList(valueStruct, complexObjectArrayBuffer, internalValueOi);
   }
   return result;
 }
 private void debugDumpKeyProbe(long keyOffset, int keyLength, int hashCode, int finalSlot) {
   final int bucketMask = refs.length - 1;
   WriteBuffers.ByteSegmentRef fakeRef = new WriteBuffers.ByteSegmentRef(keyOffset, keyLength);
   writeBuffers.populateValue(fakeRef);
   int slot = hashCode & bucketMask;
   long probeSlot = slot;
   StringBuilder sb = new StringBuilder("Probe path debug for [");
   sb.append(
       Utils.toStringBinary(fakeRef.getBytes(), (int) fakeRef.getOffset(), fakeRef.getLength()));
   sb.append("] hashCode ").append(Integer.toBinaryString(hashCode)).append(" is: ");
   int i = 0;
   while (slot != finalSlot) {
     probeSlot += (++i);
     slot = (int) (probeSlot & bucketMask);
     sb.append(slot)
         .append(" - ")
         .append(probeSlot)
         .append(" - ")
         .append(Long.toBinaryString(refs[slot]))
         .append("\n");
   }
   LOG.info(sb.toString());
 }