test_class.declarator: HASH_SLOT_NUM = 100
test_class.modifier: private final
test_class.original_string: private final int HASH_SLOT_NUM = 100;
test_class.type: int
test_class.var_name: HASH_SLOT_NUM
test_class.declarator: INDEX_NUM = 400
test_class.modifier: private final
test_class.original_string: private final int INDEX_NUM = 400;
test_class.type: int
test_class.var_name: INDEX_NUM
test_class.file: store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java
test_class.identifier: IndexFileTest
test_case.body: @Test
      public void testPutKey() throws Exception {
          IndexFile indexFile = new IndexFile("100", HASH_SLOT_NUM, INDEX_NUM, 0, 0);
          for (long i = 0; i < (INDEX_NUM - 1); i++) {
              boolean putResult = indexFile.putKey(Long.toString(i), i, System.currentTimeMillis());
              assertThat(putResult).isTrue();
          }
  
          // put over index file capacity.
          boolean putResult = indexFile.putKey(Long.toString(400), 400, System.currentTimeMillis());
          assertThat(putResult).isFalse();
          indexFile.destroy(0);
          File file = new File("100");
          UtilAll.deleteFile(file);
      }
test_case.class_method_signature: IndexFileTest.testPutKey()
test_case.full_signature: @Test public void testPutKey()
test_case.identifier: testPutKey
test_case.invocations: putKey toString currentTimeMillis isTrue assertThat putKey toString currentTimeMillis isFalse assertThat destroy deleteFile
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testPutKey()
focal_class.declarator: log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: hashSlotSize = 4
focal_class.modifier: private static
focal_class.original_string: private static int hashSlotSize = 4;
focal_class.type: int
focal_class.var_name: hashSlotSize
focal_class.declarator: indexSize = 20
focal_class.modifier: private static
focal_class.original_string: private static int indexSize = 20;
focal_class.type: int
focal_class.var_name: indexSize
focal_class.declarator: invalidIndex = 0
focal_class.modifier: private static
focal_class.original_string: private static int invalidIndex = 0;
focal_class.type: int
focal_class.var_name: invalidIndex
focal_class.declarator: hashSlotNum
focal_class.modifier: private final
focal_class.original_string: private final int hashSlotNum;
focal_class.type: int
focal_class.var_name: hashSlotNum
focal_class.declarator: indexNum
focal_class.modifier: private final
focal_class.original_string: private final int indexNum;
focal_class.type: int
focal_class.var_name: indexNum
focal_class.declarator: mappedFile
focal_class.modifier: private final
focal_class.original_string: private final MappedFile mappedFile;
focal_class.type: MappedFile
focal_class.var_name: mappedFile
focal_class.declarator: fileChannel
focal_class.modifier: private final
focal_class.original_string: private final FileChannel fileChannel;
focal_class.type: FileChannel
focal_class.var_name: fileChannel
focal_class.declarator: mappedByteBuffer
focal_class.modifier: private final
focal_class.original_string: private final MappedByteBuffer mappedByteBuffer;
focal_class.type: MappedByteBuffer
focal_class.var_name: mappedByteBuffer
focal_class.declarator: indexHeader
focal_class.modifier: private final
focal_class.original_string: private final IndexHeader indexHeader;
focal_class.type: IndexHeader
focal_class.var_name: indexHeader
focal_class.file: store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java
focal_class.identifier: IndexFile
focal_class.class_method_signature: IndexFile.IndexFile(final String fileName, final int hashSlotNum, final int indexNum,
          final long endPhyOffset, final long endTimestamp)
focal_class.full_signature: public  IndexFile(final String fileName, final int hashSlotNum, final int indexNum,
          final long endPhyOffset, final long endTimestamp)
focal_class.identifier: IndexFile
focal_class.modifiers: public
focal_class.parameters: (final String fileName, final int hashSlotNum, final int indexNum,
          final long endPhyOffset, final long endTimestamp)
focal_class.signature:  IndexFile(final String fileName, final int hashSlotNum, final int indexNum,
          final long endPhyOffset, final long endTimestamp)
focal_class.class_method_signature: IndexFile.getFileName()
focal_class.full_signature: public String getFileName()
focal_class.identifier: getFileName
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getFileName()
focal_class.class_method_signature: IndexFile.load()
focal_class.full_signature: public void load()
focal_class.identifier: load
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void load()
focal_class.class_method_signature: IndexFile.flush()
focal_class.full_signature: public void flush()
focal_class.identifier: flush
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void flush()
focal_class.class_method_signature: IndexFile.isWriteFull()
focal_class.full_signature: public boolean isWriteFull()
focal_class.identifier: isWriteFull
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isWriteFull()
focal_class.class_method_signature: IndexFile.destroy(final long intervalForcibly)
focal_class.full_signature: public boolean destroy(final long intervalForcibly)
focal_class.identifier: destroy
focal_class.modifiers: public
focal_class.parameters: (final long intervalForcibly)
focal_class.return: boolean
focal_class.signature: boolean destroy(final long intervalForcibly)
focal_class.class_method_signature: IndexFile.putKey(final String key, final long phyOffset, final long storeTimestamp)
focal_class.full_signature: public boolean putKey(final String key, final long phyOffset, final long storeTimestamp)
focal_class.identifier: putKey
focal_class.modifiers: public
focal_class.parameters: (final String key, final long phyOffset, final long storeTimestamp)
focal_class.return: boolean
focal_class.signature: boolean putKey(final String key, final long phyOffset, final long storeTimestamp)
focal_class.class_method_signature: IndexFile.indexKeyHashMethod(final String key)
focal_class.full_signature: public int indexKeyHashMethod(final String key)
focal_class.identifier: indexKeyHashMethod
focal_class.modifiers: public
focal_class.parameters: (final String key)
focal_class.return: int
focal_class.signature: int indexKeyHashMethod(final String key)
focal_class.class_method_signature: IndexFile.getBeginTimestamp()
focal_class.full_signature: public long getBeginTimestamp()
focal_class.identifier: getBeginTimestamp
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: long
focal_class.signature: long getBeginTimestamp()
focal_class.class_method_signature: IndexFile.getEndTimestamp()
focal_class.full_signature: public long getEndTimestamp()
focal_class.identifier: getEndTimestamp
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: long
focal_class.signature: long getEndTimestamp()
focal_class.class_method_signature: IndexFile.getEndPhyOffset()
focal_class.full_signature: public long getEndPhyOffset()
focal_class.identifier: getEndPhyOffset
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: long
focal_class.signature: long getEndPhyOffset()
focal_class.class_method_signature: IndexFile.isTimeMatched(final long begin, final long end)
focal_class.full_signature: public boolean isTimeMatched(final long begin, final long end)
focal_class.identifier: isTimeMatched
focal_class.modifiers: public
focal_class.parameters: (final long begin, final long end)
focal_class.return: boolean
focal_class.signature: boolean isTimeMatched(final long begin, final long end)
focal_class.class_method_signature: IndexFile.selectPhyOffset(final List<Long> phyOffsets, final String key, final int maxNum,
          final long begin, final long end, boolean lock)
focal_class.full_signature: public void selectPhyOffset(final List<Long> phyOffsets, final String key, final int maxNum,
          final long begin, final long end, boolean lock)
focal_class.identifier: selectPhyOffset
focal_class.modifiers: public
focal_class.parameters: (final List<Long> phyOffsets, final String key, final int maxNum,
          final long begin, final long end, boolean lock)
focal_class.return: void
focal_class.signature: void selectPhyOffset(final List<Long> phyOffsets, final String key, final int maxNum,
          final long begin, final long end, boolean lock)
focal_method.body: public boolean putKey(final String key, final long phyOffset, final long storeTimestamp) {
          if (this.indexHeader.getIndexCount() < this.indexNum) {
              int keyHash = indexKeyHashMethod(key);
              int slotPos = keyHash % this.hashSlotNum;
              int absSlotPos = IndexHeader.INDEX_HEADER_SIZE + slotPos * hashSlotSize;
  
              FileLock fileLock = null;
  
              try {
  
                  // fileLock = this.fileChannel.lock(absSlotPos, hashSlotSize,
                  // false);
                  int slotValue = this.mappedByteBuffer.getInt(absSlotPos);
                  if (slotValue <= invalidIndex || slotValue > this.indexHeader.getIndexCount()) {
                      slotValue = invalidIndex;
                  }
  
                  long timeDiff = storeTimestamp - this.indexHeader.getBeginTimestamp();
  
                  timeDiff = timeDiff / 1000;
  
                  if (this.indexHeader.getBeginTimestamp() <= 0) {
                      timeDiff = 0;
                  } else if (timeDiff > Integer.MAX_VALUE) {
                      timeDiff = Integer.MAX_VALUE;
                  } else if (timeDiff < 0) {
                      timeDiff = 0;
                  }
  
                  int absIndexPos =
                      IndexHeader.INDEX_HEADER_SIZE + this.hashSlotNum * hashSlotSize
                          + this.indexHeader.getIndexCount() * indexSize;
  
                  this.mappedByteBuffer.putInt(absIndexPos, keyHash);
                  this.mappedByteBuffer.putLong(absIndexPos + 4, phyOffset);
                  this.mappedByteBuffer.putInt(absIndexPos + 4 + 8, (int) timeDiff);
                  this.mappedByteBuffer.putInt(absIndexPos + 4 + 8 + 4, slotValue);
  
                  this.mappedByteBuffer.putInt(absSlotPos, this.indexHeader.getIndexCount());
  
                  if (this.indexHeader.getIndexCount() <= 1) {
                      this.indexHeader.setBeginPhyOffset(phyOffset);
                      this.indexHeader.setBeginTimestamp(storeTimestamp);
                  }
  
                  this.indexHeader.incHashSlotCount();
                  this.indexHeader.incIndexCount();
                  this.indexHeader.setEndPhyOffset(phyOffset);
                  this.indexHeader.setEndTimestamp(storeTimestamp);
  
                  return true;
              } catch (Exception e) {
                  log.error("putKey exception, Key: " + key + " KeyHashCode: " + key.hashCode(), e);
              } finally {
                  if (fileLock != null) {
                      try {
                          fileLock.release();
                      } catch (IOException e) {
                          log.error("Failed to release the lock", e);
                      }
                  }
              }
          } else {
              log.warn("Over index file capacity: index count = " + this.indexHeader.getIndexCount()
                  + "; index max num = " + this.indexNum);
          }
  
          return false;
      }
focal_method.class_method_signature: IndexFile.putKey(final String key, final long phyOffset, final long storeTimestamp)
focal_method.full_signature: public boolean putKey(final String key, final long phyOffset, final long storeTimestamp)
focal_method.identifier: putKey
focal_method.invocations: getIndexCount indexKeyHashMethod getInt getIndexCount getBeginTimestamp getBeginTimestamp getIndexCount putInt putLong putInt putInt putInt getIndexCount getIndexCount setBeginPhyOffset setBeginTimestamp incHashSlotCount incIndexCount setEndPhyOffset setEndTimestamp error hashCode release error warn getIndexCount
focal_method.modifiers: public
focal_method.parameters: (final String key, final long phyOffset, final long storeTimestamp)
focal_method.return: boolean
focal_method.signature: boolean putKey(final String key, final long phyOffset, final long storeTimestamp)