labuladong commented on PR #18390:
URL: https://github.com/apache/pulsar/pull/18390#issuecomment-1310373755

   
   > In the `rehash` method, the member `this.table` of `Section` will be 
reallocated a new long[] array, which is different from old table member.
   > 
   > ```
   >         private void rehash(int newCapacity) {
   >             long[] newTable = new long[4 * newCapacity];
   >             ...
   >             table = newTable;
   >             ...
   >         }
   > ```
   
   This inspires me. Can we fix the `get` issue in the same way? 
   
   
   ```java
               // add local variable here, so OutOfBound won't happen
               long[] table = this.table;
               int bucket = signSafeMod(keyHash, capacity);
   
               try {
                   while (true) {
                       long storedKey1 = table[bucket];
                       long storedKey2 = table[bucket + 1];
                       long storedValue1 = table[bucket + 2];
                       long storedValue2 = table[bucket + 3];
                       
                       // compare table to ensure not rehash
                       if (!acquiredLock && validate(stamp) && table == 
this.table) {
                           if (key1 == storedKey1 && key2 == storedKey2) {
                               return new LongPair(storedValue1, storedValue2);
                           } else if (storedKey1 == EmptyKey) {
                               return null;
                           }
                       } else {
                           if (!acquiredLock) {
                               stamp = readLock();
                               acquiredLock = true;
                               // update local variable
                               table = this.table;
   
                               bucket = signSafeMod(keyHash, capacity);
                               storedKey1 = table[bucket];
                               storedKey2 = table[bucket + 1];
                               storedValue1 = table[bucket + 2];
                               storedValue2 = table[bucket + 3];
                           }
   ```
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to