private void finalizeDiscardResult(
      Arena arena, DiscardContext ctx, int freeListIx, int newlyFreeHeaderIx) {
    int maxHeaderIx = newlyFreeHeaderIx + (1 << freeListIx);
    if (assertsEnabled) {
      arena.checkHeader(newlyFreeHeaderIx, -1, true);
    }
    arena.unsetHeaders(newlyFreeHeaderIx + 1, maxHeaderIx, CasLog.Src.CLEARED_VICTIM);
    // Set the leftmost header of the base and its buddy (that are now being merged).
    arena.setHeaderNoBufAlloc(newlyFreeHeaderIx, freeListIx, CasLog.Src.NEWLY_CLEARED);
    ctx.addResult(arena.arenaIx, newlyFreeHeaderIx);
  }
Sets the headers correctly for a newly-freed buffer after discarding stuff.
llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java