Skip to content

Commit

Permalink
IGNITE-14823 Buffer abbrevation (#11089)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Dec 12, 2023
1 parent b7c36c9 commit 34b9616
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 47 deletions.
2 changes: 1 addition & 1 deletion modules/checkstyle/src/main/resources/abbrevations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ arguments,args
array,arr
attribute,attr
attributes,attrs
#buffer,buf
buffer,buf
#class,cls
#command,cmd
#config,cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ private ByteBuffer doCompactPage(ByteBuffer page, int pageSize) throws IgniteChe

/** Check if filesystem actually supports punching holes. */
private void checkPunchHole(Path storagePath, int fsBlockSz) throws IgniteException {
ByteBuffer buffer = null;
ByteBuffer buf = null;
File testFile = null;
try {
testFile = File.createTempFile("punch_hole_", null, storagePath.toFile());

buffer = GridUnsafe.allocateBuffer(fsBlockSz * 2);
GridUnsafe.zeroMemory(GridUnsafe.bufferAddress(buffer), buffer.capacity());
buf = GridUnsafe.allocateBuffer(fsBlockSz * 2);
GridUnsafe.zeroMemory(GridUnsafe.bufferAddress(buf), buf.capacity());

try (RandomAccessFileIO testFileIO = new RandomAccessFileIO(testFile, CREATE, WRITE)) {
testFileIO.writeFully(buffer);
testFileIO.writeFully(buf);

testFileIO.punchHole(fsBlockSz, fsBlockSz);
}
Expand All @@ -190,8 +190,8 @@ private void checkPunchHole(Path storagePath, int fsBlockSz) throws IgniteExcept
throw new IgniteException("File system does not support punching holes on path " + storagePath, e);
}
finally {
if (buffer != null)
GridUnsafe.freeBuffer(buffer);
if (buf != null)
GridUnsafe.freeBuffer(buf);

if (testFile != null)
testFile.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,12 @@ private long usedCheckpointBufferPages() {
if (F.isEmpty(regionMetrics0))
return 0;

long usedCheckpointBufferPages = 0L;
long usedCheckpointBufPages = 0L;

for (DataRegionMetrics rm : regionMetrics0)
usedCheckpointBufferPages += rm.getUsedCheckpointBufferPages();
usedCheckpointBufPages += rm.getUsedCheckpointBufferPages();

return usedCheckpointBufferPages;
return usedCheckpointBufPages;
}

/**
Expand All @@ -577,12 +577,12 @@ private long usedCheckpointBufferSize() {
if (F.isEmpty(regionMetrics0))
return 0;

long usedCheckpointBufferSize = 0L;
long usedCheckpointBufSize = 0L;

for (DataRegionMetrics rm : regionMetrics0)
usedCheckpointBufferSize += rm.getUsedCheckpointBufferSize();
usedCheckpointBufSize += rm.getUsedCheckpointBufferSize();

return usedCheckpointBufferSize;
return usedCheckpointBufSize;
}

/**
Expand All @@ -599,12 +599,12 @@ private long checkpointBufferSize() {
if (F.isEmpty(regionMetrics0))
return 0;

long checkpointBufferSize = 0L;
long checkpointBufSize = 0L;

for (DataRegionMetrics rm : regionMetrics0)
checkpointBufferSize += rm.getCheckpointBufferSize();
checkpointBufSize += rm.getCheckpointBufferSize();

return checkpointBufferSize;
return checkpointBufSize;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public class ByteBufferExpander implements AutoCloseable {
* @param order Byte order.
*/
public ByteBufferExpander(int initSize, ByteOrder order) {
ByteBuffer buffer = GridUnsafe.allocateBuffer(initSize);
buffer.order(order);

buf = buffer;
buf = GridUnsafe.allocateBuffer(initSize);
buf.order(order);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public ClientDataStreamerStartRequest(BinaryReaderExImpl reader) {
boolean skipStore = (flags & SKIP_STORE) != 0;

// Don't use thread buffer for a one-off streamer operation.
boolean useThreadBuffer = !close;
boolean useThreadBuf = !close;

if (perNodeBufferSize >= 0)
dataStreamer.perNodeBufferSize(perNodeBufferSize);
else if (entries != null && !entries.isEmpty() && close)
dataStreamer.perNodeBufferSize(entries.size());

if (perThreadBufferSize >= 0 && useThreadBuffer)
if (perThreadBufferSize >= 0 && useThreadBuf)
dataStreamer.perThreadBufferSize(perThreadBufferSize);

dataStreamer.allowOverwrite(allowOverwrite);
Expand All @@ -116,7 +116,7 @@ else if (entries != null && !entries.isEmpty() && close)
dataStreamer.receiver(createReceiver(ctx.kernalContext(), receiverObj, receiverPlatform, keepBinary));

if (entries != null)
dataStreamer.addDataInternal(entries, useThreadBuffer);
dataStreamer.addDataInternal(entries, useThreadBuf);

if (flush)
dataStreamer.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1318,12 +1318,12 @@ static String[] splitOnTokens(String text) {

char[] arr = text.toCharArray();
ArrayList<String> list = new ArrayList<String>();
StringBuilder buffer = new StringBuilder();
StringBuilder buf = new StringBuilder();
for (int i = 0; i < arr.length; i++) {
if (arr[i] == '?' || arr[i] == '*') {
if (buffer.length() != 0) {
list.add(buffer.toString());
buffer.setLength(0);
if (buf.length() != 0) {
list.add(buf.toString());
buf.setLength(0);
}
if (arr[i] == '?')
list.add("?");
Expand All @@ -1332,10 +1332,10 @@ else if (list.isEmpty() ||
list.add("*");
}
else
buffer.append(arr[i]);
buf.append(arr[i]);
}
if (buffer.length() != 0)
list.add(buffer.toString());
if (buf.length() != 0)
list.add(buf.toString());

return list.toArray( new String[ list.size() ] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public void testCacheSize() throws Exception {

Marshaller marshaller = grid(0).context().config().getMarshaller();

byte[] buffer = marshaller.marshal(msg);
byte[] buf = marshaller.marshal(msg);

Object readObject = marshaller.unmarshal(buffer, getClass().getClassLoader());
Object readObject = marshaller.unmarshal(buf, getClass().getClassLoader());

assertTrue(readObject instanceof TcpDiscoveryMetricsUpdateMessage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ public void wakeupThrottledThread() throws IgniteInterruptedCheckedException {

when(pageMemory2g.checkpointBufferPagesSize()).thenReturn(100);

AtomicInteger checkpointBufferPagesCount = new AtomicInteger(70);
AtomicInteger checkpointBufPagesCount = new AtomicInteger(70);

when(pageMemory2g.checkpointBufferPagesCount()).thenAnswer(mock -> checkpointBufferPagesCount.get());
when(pageMemory2g.checkpointBufferPagesCount()).thenAnswer(mock -> checkpointBufPagesCount.get());

try {
loadThreads.forEach(Thread::start);
Expand All @@ -404,7 +404,7 @@ public void wakeupThrottledThread() throws IgniteInterruptedCheckedException {
assertTrue(t.getName(), waitForCondition(() -> t.getState() == TIMED_WAITING, 500L));

// Disable throttling
checkpointBufferPagesCount.set(50);
checkpointBufPagesCount.set(50);

// Awaiting that all load threads are unparked.
for (Thread t : loadThreads)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void runThrottlingEmptifyCpBufFirst(PageMemoryImpl.ThrottlingPolicy plc)
int pagesForStartThrottling = 10;

//Number of pages which were poll from checkpoint buffer for throttling.
AtomicInteger cpBufferPollPages = new AtomicInteger();
AtomicInteger cpBufPollPages = new AtomicInteger();

// Create a 1 mb page memory.
PageMemoryImpl memory = createPageMemory(
Expand All @@ -290,7 +290,7 @@ public void runThrottlingEmptifyCpBufFirst(PageMemoryImpl.ThrottlingPolicy plc)
(IgniteInClosure<FullPageId>)fullPageId -> {
//First increment then get because pageStoreMgr.storedPages always contains at least one page
// which was written before throttling.
assertEquals(cpBufferPollPages.incrementAndGet(), pageStoreMgr.storedPages.size());
assertEquals(cpBufPollPages.incrementAndGet(), pageStoreMgr.storedPages.size());
}
);

Expand All @@ -317,7 +317,7 @@ public void runThrottlingEmptifyCpBufFirst(PageMemoryImpl.ThrottlingPolicy plc)
// from checkpoint buffer before throttling will be disabled but at least one page always would be written
// outside of throttling and in our case we certainly know that this page is also contained in checkpoint buffer
// (because all of our pages are in checkpoint buffer).
assertEquals(pagesForStartThrottling - 1, cpBufferPollPages.get());
assertEquals(pagesForStartThrottling - 1, cpBufPollPages.get());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ private void testPutGet(Value v1, Value v2, Value v3) throws Exception {
* @return Random string.
*/
private String randomString(int cnt) {
final char[] buffer = new char[cnt];
final char[] buf = new char[cnt];

ThreadLocalRandom rnd = ThreadLocalRandom.current();

Expand All @@ -935,29 +935,29 @@ private String randomString(int cnt) {
cnt++;
else {
// low surrogate, insert high surrogate after putting it in
buffer[cnt] = ch;
buf[cnt] = ch;
cnt--;
buffer[cnt] = (char)(55296 + rnd.nextInt(128));
buf[cnt] = (char)(55296 + rnd.nextInt(128));
}
}
else if (ch >= 55296 && ch <= 56191) {
if (cnt == 0)
cnt++;
else {
// high surrogate, insert low surrogate before putting it in
buffer[cnt] = (char)(56320 + rnd.nextInt(128));
buf[cnt] = (char)(56320 + rnd.nextInt(128));
cnt--;
buffer[cnt] = ch;
buf[cnt] = ch;
}
}
else if (ch >= 56192 && ch <= 56319)
// private high surrogate, no effing clue, so skip it
cnt++;
else
buffer[cnt] = ch;
buf[cnt] = ch;
}

return new String(buffer);
return new String(buf);
}

/** Test class to verify java object inlining */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ private static boolean verifyEntry(JarEntry jarEntry, Manifest manifest, PublicK
* @throws IOException Thrown if read fails.
*/
private static void verifyDigestsImplicitly(InputStream in) throws IOException {
byte[] buffer = new byte[BUF_SIZE];
byte[] buf = new byte[BUF_SIZE];

while (in.read(buffer, 0, buffer.length) != -1) {
while (in.read(buf, 0, buf.length) != -1) {
// Just read the entry. Will throw a SecurityException if signature
// or digest check fails. Since we instantiated JarFile with parameter
// true, that tells it to verify that the files match the digests
Expand Down

0 comments on commit 34b9616

Please sign in to comment.