diff --git a/llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java b/llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java index a27964f..5dee2f9 100644 --- a/llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java +++ b/llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java @@ -131,8 +131,11 @@ public BuddyAllocator(boolean isDirectVal, boolean isMappedVal, int minAllocVal, maxAllocation = maxAllocVal; if (isMapped) { try { - cacheDir = Files.createTempDirectory( - FileSystems.getDefault().getPath(mapPath), "llap-", RWX); + Path path = FileSystems.getDefault().getPath(mapPath); + if (!Files.exists(path)) { + Files.createDirectory(path); + } + cacheDir = Files.createTempDirectory(path, "llap-", RWX); } catch (IOException ioe) { // conf validator already checks this, so it will never trigger usually throw new AssertionError("Configured mmap directory should be writable", ioe); @@ -558,7 +561,7 @@ private void discardAllBuffersFromCtx(Arena arena, DiscardContext ctx) { /** * Unlocks the buffer after the discard has been abandoned. */ - private void cancelDiscard(LlapAllocatorBuffer buf, int arenaIx, int headerIx) { + private void cancelDiscard(LlapAllocatorBuffer buf, int arenaIx) { Boolean result = buf.cancelDiscard(); if (result == null) return; // If the result is not null, the buffer was evicted during the move. @@ -982,12 +985,12 @@ private void abandonOneHeaderBeingMoved(int headerIx, CasLog.Src src) { if (assertsEnabled) { assertBufferLooksValid(freeListIx, buf, arenaIx, headerIx); } - cancelDiscard(buf, arenaIx, headerIx); + cancelDiscard(buf, arenaIx); } else { if (assertsEnabled) { checkHeader(headerIx, -1, true); } - addToFreeListWithMerge(headerIx, freeListIx, null, src); + addToFreeListWithMerge(headerIx, freeListIx, src); } } @@ -1249,7 +1252,7 @@ private int allocateWithSplit(int freeListIx, MemoryBuffer[] dest, lastSplitNextHeader = headerIx; // If anything remains, this is where it starts. headerIx = getNextFreeListItem(origOffset); } - replaceListHeadUnderLock(splitList, headerIx, splitListIx); // In the end, update free list head. + replaceListHeadUnderLock(splitList, headerIx); // In the end, update free list head. } finally { splitList.lock.unlock(); } @@ -1265,7 +1268,7 @@ private int allocateWithSplit(int freeListIx, MemoryBuffer[] dest, int newListIndex = freeListIx; while (lastSplitBlocksRemaining > 0) { if ((lastSplitBlocksRemaining & 1) == 1) { - addToFreeListWithMerge(lastSplitNextHeader, newListIndex, null, src); + addToFreeListWithMerge(lastSplitNextHeader, newListIndex, src); lastSplitNextHeader += (1 << newListIndex); } lastSplitBlocksRemaining >>>= 1; @@ -1284,7 +1287,7 @@ private void initializeNewlyAllocated( buffer.setNewAllocLocation(arenaIx, headerIx); } - private void replaceListHeadUnderLock(FreeList freeList, int headerIx, int ix) { + private void replaceListHeadUnderLock(FreeList freeList, int headerIx) { if (headerIx == freeList.listHead) return; if (headerIx >= 0) { int newHeadOffset = offsetFromHeaderIndex(headerIx); @@ -1354,7 +1357,7 @@ public int allocateFromFreeListUnderLock(FreeList freeList, int freeListIx, } ++destIx; } - replaceListHeadUnderLock(freeList, current, freeListIx); + replaceListHeadUnderLock(freeList, current); return destIx; } @@ -1383,12 +1386,11 @@ public void deallocate(LlapAllocatorBuffer buffer, boolean isAfterMove) { checkHeader(headerIx, freeListIx, true); } buffers[headerIx] = null; - addToFreeListWithMerge(headerIx, freeListIx, buffer, CasLog.Src.DEALLOC); + addToFreeListWithMerge(headerIx, freeListIx, CasLog.Src.DEALLOC); } } - private void addToFreeListWithMerge(int headerIx, int freeListIx, - LlapAllocatorBuffer buffer, CasLog.Src src) { + private void addToFreeListWithMerge(int headerIx, int freeListIx, CasLog.Src src) { while (true) { FreeList freeList = freeLists[freeListIx]; int bHeaderIx = getBuddyHeaderIx(freeListIx, headerIx); diff --git a/llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocator.java b/llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocator.java index b3179c0..51577bd 100644 --- a/llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocator.java +++ b/llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocator.java @@ -179,6 +179,13 @@ public Void call() throws Exception { } } + @Test + public void testCachedirCreated() throws Exception { + int min = 3, max = 8, maxAlloc = 1 << max; + new BuddyAllocator(isDirect, isMapped, 1 << min, maxAlloc, maxAlloc, maxAlloc, 0, tmpDir + "/testifcreated", + new DummyMemoryManager(), LlapDaemonCacheMetrics.create("test", "1"), null); + } + static void syncThreadStart(final CountDownLatch cdlIn, final CountDownLatch cdlOut) { cdlIn.countDown(); try {