fix for inaccurate page calculation in bin overflow

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@632651 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-03-01 19:59:49 +00:00
parent 32dc290eb7
commit 767b548715
1 changed files with 9 additions and 9 deletions

View File

@ -183,10 +183,12 @@ class HashBin {
private void addHashEntry(int index, HashEntry entry) throws IOException { private void addHashEntry(int index, HashEntry entry) throws IOException {
HashPageInfo pageToUse = null; HashPageInfo pageToUse = null;
int offset = 0; int offset = 0;
if (index >= maximumBinSize()) { if (index >= getMaximumBinSize()) {
HashPage hp = hashIndex.createPage(id); while(index >= getMaximumBinSize()) {
pageToUse = addHashPageInfo(hp.getId(), 0); HashPage hp = hashIndex.createPage(id);
pageToUse.setPage(hp); pageToUse = addHashPageInfo(hp.getId(), 0);
pageToUse.setPage(hp);
}
offset = 0; offset = 0;
} else { } else {
int count = 0; int count = 0;
@ -239,7 +241,7 @@ class HashBin {
} }
private int maximumBinSize() { private int getMaximumBinSize() {
return maximumEntries * hashPages.size(); return maximumEntries * hashPages.size();
} }
@ -264,7 +266,6 @@ class HashBin {
int count = 0; int count = 0;
for (HashPageInfo page : hashPages) { for (HashPageInfo page : hashPages) {
if ((index + 1) <= (count + page.size())) { if ((index + 1) <= (count + page.size())) {
// count=count==0?count:count+1;
result = index - count; result = index - count;
break; break;
} }
@ -274,13 +275,12 @@ class HashBin {
} }
private void doOverFlow(int index) throws IOException { private void doOverFlow(int index) throws IOException {
int pageNo = index / maximumEntries; HashPageInfo info = getRetrievePage(index);
HashPageInfo info = hashPages.get(pageNo);
if (info.size() > maximumEntries) { if (info.size() > maximumEntries) {
// overflowed // overflowed
info.begin(); info.begin();
HashEntry entry = info.removeHashEntry(info.size() - 1); HashEntry entry = info.removeHashEntry(info.size() - 1);
doOverFlow(pageNo + 1, entry); doOverFlow(hashPages.indexOf(info) + 1, entry);
} }
} }