diff --git a/build.gradle b/build.gradle index 00feb71be..9f35e864b 100644 --- a/build.gradle +++ b/build.gradle @@ -688,8 +688,8 @@ if (!rootProject.hasProperty('store')) { task generateSources { dependsOn subprojectBase + 'gemfire-jgroups:jgMagic' - dependsOn subprojectBase + 'gemfire-util:compileJava' dependsOn subprojectBase + 'gemfire-core:createVersionPropertiesFile' + dependsOn subprojectBase + 'snappydata-util:compileJava' dependsOn subprojectBase + 'snappydata-store-core:compileJavacc' dependsOn subprojectBase + 'snappydata-store-core:generatePropertiesFiles' dependsOn subprojectBase + 'gemfire-core:createVersionPropertiesFile' diff --git a/gemfire-core/build.gradle b/gemfire-core/build.gradle index cadb91ffa..e6f1a908d 100644 --- a/gemfire-core/build.gradle +++ b/gemfire-core/build.gradle @@ -127,6 +127,7 @@ dependencies { compile project(subprojectBase + 'gemfire-util') compile project(subprojectBase + 'gemfire-shared') compile project(subprojectBase + 'gemfire-trove') + compile project(subprojectBase + 'snappydata-util') jcaCompile sourceSets.main.output } diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisor.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisor.java index 1dadf623b..62186df38 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisor.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisor.java @@ -45,7 +45,7 @@ import com.gemstone.gemfire.internal.cache.persistence.PersistentMemberID; import com.gemstone.gemfire.internal.cache.versions.VersionSource; import com.gemstone.gemfire.internal.i18n.LocalizedStrings; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.gemstone.gemfire.internal.shared.Version; import com.gemstone.gemfire.internal.util.ArrayUtils; diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/jgroup/JGroupMembershipManager.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/jgroup/JGroupMembershipManager.java index 31d52f523..19c124a32 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/jgroup/JGroupMembershipManager.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/jgroup/JGroupMembershipManager.java @@ -84,7 +84,6 @@ import com.gemstone.gemfire.internal.tcp.Stub; import com.gemstone.gemfire.internal.tcp.TCPConduit; import com.gemstone.gemfire.internal.util.Breadcrumbs; -import com.gemstone.gnu.trove.TIntObjectHashMap; import com.gemstone.org.jgroups.Address; import com.gemstone.org.jgroups.Channel; import com.gemstone.org.jgroups.ChannelClosedException; @@ -111,6 +110,7 @@ import com.gemstone.org.jgroups.stack.ProtocolStack; import com.gemstone.org.jgroups.util.GemFireTracer; import com.gemstone.gnu.trove.TObjectProcedure; +import io.snappydata.collection.LongObjectHashMap; public final class JGroupMembershipManager implements MembershipManager { @@ -3293,13 +3293,13 @@ public Set send(InternalDistributedMember[] destinations, calculatedMembers.add((JGroupMember)destinations[i].getNetMember()); } } // send to explicit list - TIntObjectHashMap messages = new TIntObjectHashMap(); + LongObjectHashMap messages = LongObjectHashMap.withExpectedSize(2); long startSer = theStats.startMsgSerialization(); boolean firstMessage = true; for (Iterator it=calculatedMembers.iterator(); it.hasNext(); ) { JGroupMember mbr = (JGroupMember)it.next(); short version = mbr.getAddress().getVersionOrdinal(); - if ( !messages.containsKey(version) ) { + if (!messages.contains(version)) { Message jmsg = createJGMessage(msg, local, version); messages.put(version, jmsg); if (firstMessage) { @@ -3316,7 +3316,7 @@ public Set send(InternalDistributedMember[] destinations, JGroupMember mbr = it.next(); IpAddress to = mbr.getAddress(); short version = to.getVersionOrdinal(); - Message jmsg = (Message)messages.get(version); + Message jmsg = messages.get(version); if (DistributionManager.VERBOSE || logger.fineEnabled()) logger.info( LocalizedStrings.DEBUG, diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/CopyOnWriteHashSet.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/CopyOnWriteHashSet.java index d75a9c233..d4bf0a9d3 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/CopyOnWriteHashSet.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/CopyOnWriteHashSet.java @@ -25,7 +25,7 @@ import java.util.Iterator; import java.util.Set; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; /** * A Hash set where every modification makes an internal copy diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DSFIDFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DSFIDFactory.java index a1684ea50..2f37cc968 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DSFIDFactory.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DSFIDFactory.java @@ -125,11 +125,11 @@ import com.gemstone.gemfire.pdx.internal.CheckTypeRegistryState; import com.gemstone.gemfire.pdx.internal.EnumId; import com.gemstone.gemfire.pdx.internal.EnumInfo; -import com.gemstone.gnu.trove.TIntObjectHashMap; import com.gemstone.org.jgroups.View; import com.gemstone.org.jgroups.protocols.pbcast.JoinRsp; import com.gemstone.org.jgroups.stack.IpAddress; import com.gemstone.org.jgroups.util.StreamableFixedID; +import io.snappydata.collection.LongObjectHashMap; import java.io.DataInput; import java.io.DataOutput; @@ -169,7 +169,8 @@ public Version[] getSerializationVersions() { private static volatile boolean typesRegistered; private static final Supplier[] dsfidMap = new Supplier[256]; - private static final TIntObjectHashMap dsfidMap2 = new TIntObjectHashMap(800); + private static final LongObjectHashMap> dsfidMap2 = + LongObjectHashMap.withExpectedSize(512); static { if (!InternalDistributedSystem.isHadoopGfxdLonerMode()) { @@ -863,14 +864,14 @@ public static Object create(int dsfid, DataInput in) if (dsfid >= Byte.MIN_VALUE && dsfid <= Byte.MAX_VALUE) { creator = dsfidMap[dsfid + Byte.MAX_VALUE + 1]; } else { - creator = (Supplier)dsfidMap2.get(dsfid); + creator = dsfidMap2.get(dsfid); } if (creator == null && !typesRegistered) { registerTypes(); if (dsfid >= Byte.MIN_VALUE && dsfid <= Byte.MAX_VALUE) { creator = dsfidMap[dsfid + Byte.MAX_VALUE + 1]; } else { - creator = (Supplier)dsfidMap2.get(dsfid); + creator = dsfidMap2.get(dsfid); } } if (creator != null) { @@ -1130,7 +1131,7 @@ static Supplier[] getDsfidmap() { return dsfidMap; } - static TIntObjectHashMap getDsfidmap2() { + static LongObjectHashMap> getDsfidmap2() { return dsfidMap2; } } diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/CacheServerLauncher.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/CacheServerLauncher.java index 6ccaebd20..aef31af71 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/CacheServerLauncher.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/CacheServerLauncher.java @@ -51,7 +51,7 @@ import com.gemstone.gemfire.internal.process.StartupStatusListener; import com.gemstone.gemfire.internal.shared.LauncherBase; import com.gemstone.gemfire.internal.shared.NativeCalls; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.gemstone.gemfire.internal.util.JavaCommandBuilder; import static com.gemstone.gemfire.internal.cache.Status.*; diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskInitFile.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskInitFile.java index 25b84b9ae..4f646edac 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskInitFile.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskInitFile.java @@ -75,7 +75,7 @@ import com.gemstone.gnu.trove.TIntHashSet; import com.gemstone.gnu.trove.TLongHashSet; import com.gemstone.gnu.trove.TLongIterator; -import io.snappydata.collection.IntObjectHashMap; +import io.snappydata.collection.LongObjectHashMap; /** * Does all the IF file work for a DiskStoreImpl. @@ -1837,14 +1837,15 @@ private void savePRConfigs() { this.ifTotalRecordCount++; } } - + private void saveCanonicalIds() { - IntObjectHashMap mappings = canonicalIdHolder.getAllMappings(); - for (Map.Entry e : mappings.entrySet()) { - writeCanonicalId(e.getKey(), e.getValue()); - } + LongObjectHashMap mappings = canonicalIdHolder.getAllMappings(); + mappings.forEachWhile((id, v) -> { + writeCanonicalId((int)id, v); + return true; + }); } - + private void saveRevokedMembers() { for(PersistentMemberPattern revoked : revokedMembers) { writeRevokedMember(revoked); diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java index b10a351ce..931f4536e 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java @@ -148,7 +148,7 @@ import com.gemstone.gemfire.internal.shared.ClientSharedUtils; import com.gemstone.gemfire.internal.shared.HeapBufferAllocator; import com.gemstone.gemfire.internal.shared.NativeCalls; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.gemstone.gemfire.internal.shared.SystemProperties; import com.gemstone.gemfire.internal.shared.Version; import com.gemstone.gemfire.internal.shared.unsafe.DirectBufferAllocator; @@ -1552,30 +1552,34 @@ public Map getSnapshotRVV() { try { // Wait for all the regions to get initialized before taking snapshot. lockForSnapshotRvv.readLock().lock(); - Set regions = getApplicationRegions(); - ObjectObjectHashMap snapshot = - ObjectObjectHashMap.withExpectedSize(regions.size()); - for (LocalRegion region : regions) { - if (region.getPartitionAttributes() != null && ((PartitionedRegion)region).isDataStore() - && ((PartitionedRegion)region).concurrencyChecksEnabled) { - region.waitForData(); - for (BucketRegion br : ((PartitionedRegion)region).getDataStore().getAllLocalBucketRegions()) { - // if null then create the rvv for that bucket.! + final ObjectObjectHashMap snapshot = + ObjectObjectHashMap.withExpectedSize(this.pathToRegion.size()); + this.pathToRegion.values().forEach(region -> { + RegionVersionVector rvv; + if (region instanceof BucketRegion) { + BucketRegion br = (BucketRegion)region; + PartitionedRegion pr = br.getPartitionedRegion(); + if (pr.concurrencyChecksEnabled) { + pr.waitForData(); + // if null then create the rvv for that bucket! // For Initialization case, so that we have all the data before snapshot. br.waitForData(); - snapshot.put(br.getFullPath(), br.getVersionVector().getSnapShotOfMemberVersion()); + snapshot.put(br.getFullPath(), + br.getVersionVector().getSnapShotOfMemberVersion()); } - } else if (region.getVersionVector() != null) { - // if null then create the rvv for that region.! + } else if ((rvv = region.getVersionVector()) != null && + !region.isSecret() && !region.isUsedForMetaRegion() && + !region.isInternalRegion() && !(region instanceof HARegion) && + !region.isUsedForPartitionedRegionAdmin()) { + // if null then create the rvv for that region! // For Initialization case, so that we have all the data before snapshot. region.waitForData(); - snapshot.put(region.getFullPath(), region.getVersionVector().getSnapShotOfMemberVersion()); + snapshot.put(region.getFullPath(), rvv.getSnapShotOfMemberVersion()); } - } + }); return snapshot; } finally { lockForSnapshotRvv.readLock().unlock(); - } } diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java index 0d32c455d..c30d5b3aa 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java @@ -210,7 +210,7 @@ import com.gemstone.gemfire.internal.offheap.annotations.Retained; import com.gemstone.gemfire.internal.offheap.annotations.Unretained; import com.gemstone.gemfire.internal.sequencelog.EntryLogger; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.gemstone.gemfire.internal.shared.Version; import com.gemstone.gemfire.internal.size.ReflectionObjectSizer; import com.gemstone.gemfire.internal.size.ReflectionSingleObjectSizer; diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java index 00c542ceb..afbaaad02 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java @@ -118,7 +118,7 @@ import com.gemstone.gemfire.internal.sequencelog.EntryLogger; import com.gemstone.gemfire.internal.shared.ClientSharedUtils; import com.gemstone.gemfire.internal.shared.NativeCalls; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.gemstone.gemfire.internal.shared.UnsupportedGFXDVersionException; import com.gemstone.gemfire.internal.shared.Version; import com.gemstone.gemfire.internal.shared.unsafe.ChannelBufferUnsafeDataInputStream; diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PRHARedundancyProvider.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PRHARedundancyProvider.java index 8b899371e..46f3e04d5 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PRHARedundancyProvider.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PRHARedundancyProvider.java @@ -60,7 +60,7 @@ import com.gemstone.gemfire.internal.cache.persistence.PersistentMemberID; import com.gemstone.gemfire.internal.cache.persistence.PersistentStateListener; import com.gemstone.gemfire.internal.i18n.LocalizedStrings; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.gemstone.org.jgroups.util.StringId; /** diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/CanonicalIdHolder.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/CanonicalIdHolder.java index ff2940178..cc10d548b 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/CanonicalIdHolder.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/CanonicalIdHolder.java @@ -16,7 +16,7 @@ */ package com.gemstone.gemfire.internal.cache.persistence; -import io.snappydata.collection.IntObjectHashMap; +import io.snappydata.collection.LongObjectHashMap; import io.snappydata.collection.ObjectLongHashMap; /** @@ -33,8 +33,8 @@ public class CanonicalIdHolder { /** * Map of integer representation to canonicalized member ids. */ - private final IntObjectHashMap idToObject = - IntObjectHashMap.withExpectedSize(10); + private final LongObjectHashMap idToObject = + LongObjectHashMap.withExpectedSize(10); /** * Map of canonicalized member ids to integer representation. @@ -87,7 +87,7 @@ public int createId(Object object) { * @return a map of id to object for all objects * held by this canonical id holder. */ - public IntObjectHashMap getAllMappings() { + public LongObjectHashMap getAllMappings() { return idToObject; } } diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/versions/RegionVersionVector.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/versions/RegionVersionVector.java index c16e2eaf5..7f70a8be3 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/versions/RegionVersionVector.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/versions/RegionVersionVector.java @@ -49,7 +49,7 @@ import com.gemstone.gemfire.internal.cache.TXStateInterface; import com.gemstone.gemfire.internal.cache.persistence.DiskStoreID; import com.gemstone.gemfire.internal.i18n.LocalizedStrings; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.gemstone.gemfire.internal.shared.Version; import com.gemstone.gemfire.internal.util.concurrent.CopyOnWriteHashMap; import io.snappydata.collection.ObjectObjectHashMap; diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/AbstractStringIdResourceBundle.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/AbstractStringIdResourceBundle.java index 8c4d0eca2..8aef138e4 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/AbstractStringIdResourceBundle.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/AbstractStringIdResourceBundle.java @@ -21,13 +21,13 @@ import com.gemstone.gemfire.i18n.StringIdImpl; import com.gemstone.gemfire.internal.ClassPathLoader; import com.gemstone.org.jgroups.util.StringId; +import io.snappydata.collection.LongObjectHashMap; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Locale; -import com.gemstone.gnu.trove.TIntObjectHashMap; /** @@ -38,7 +38,7 @@ * @since 5.7 */ public class AbstractStringIdResourceBundle { - private TIntObjectHashMap data; + private LongObjectHashMap data; /** * The {@link java.util.ResourceBundle} that implements the message lookup @@ -47,8 +47,8 @@ public class AbstractStringIdResourceBundle { private static AbstractStringIdResourceBundle messageBundle; /** - * Init method to populate the TIntObjectHashMap for Non-english locales - * data = new TIntObjectHashMap(); + * Init method to populate the LongObjectHashMap for Non-english locales + * data = LongObjectHashMap.withExpectedSize(...); * * The default bundle, English, will be * data = null @@ -76,8 +76,8 @@ private void initData(String baseName, Locale l) { } } - private TIntObjectHashMap readDataFile(InputStream is) { - TIntObjectHashMap map = new TIntObjectHashMap(); + private LongObjectHashMap readDataFile(InputStream is) { + LongObjectHashMap map = LongObjectHashMap.withExpectedSize(128); boolean complete = false; BufferedReader input = null; try { @@ -129,7 +129,7 @@ private AbstractStringIdResourceBundle() { public String getString(StringId key) { if (usingRawMode()) return key.getRawText(); - String txt = (String) data.get(((StringIdImpl)key).id); + String txt = data.get(((StringIdImpl)key).id); if( txt != null ) { return txt; } else { diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/internal/BackwardCompatibilitySerializationJUnitTest.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/internal/BackwardCompatibilitySerializationJUnitTest.java index f075ed360..483b1e30a 100644 --- a/gemfire-junit/src/main/java/com/gemstone/gemfire/internal/BackwardCompatibilitySerializationJUnitTest.java +++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/internal/BackwardCompatibilitySerializationJUnitTest.java @@ -191,13 +191,13 @@ public void testAllMessages() throws Exception { // some msgs require distributed system Cache c = new CacheFactory().create(); - for (Object o : DSFIDFactory.getDsfidmap2().getValues()) { - Supplier cons = (Supplier)o; + DSFIDFactory.getDsfidmap2().forEachWhile((id, cons) -> { if (cons != null) { DataSerializableFixedID ds = (DataSerializableFixedID)cons.get(); checkSupportForRollingUpgrade(ds); } - } + return true; + }); c.close(); } diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/access/GemFireTransaction.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/access/GemFireTransaction.java index 9f039a2d4..ee738396c 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/access/GemFireTransaction.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/access/GemFireTransaction.java @@ -51,8 +51,6 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained; import com.gemstone.gemfire.internal.shared.SystemProperties; import com.gemstone.gnu.trove.TIntArrayList; -import com.gemstone.gnu.trove.TLongObjectHashMap; -import com.gemstone.gnu.trove.TLongObjectIterator; import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserver; import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserverHolder; import com.pivotal.gemfirexd.internal.engine.GfxdConstants; @@ -125,6 +123,7 @@ import com.pivotal.gemfirexd.internal.impl.store.raw.xact.XactId; import com.pivotal.gemfirexd.internal.shared.common.error.ExceptionSeverity; import com.pivotal.gemfirexd.internal.shared.common.sanity.SanityManager; +import io.snappydata.collection.LongObjectHashMap; import static com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier.GEMFIRE_TRANSACTION_BYTE_SOURCE; @@ -198,7 +197,7 @@ public final class GemFireTransaction extends RawTransaction implements private TIntArrayList freeSortIds; /** Where to look for temporary conglomerates. */ - private TLongObjectHashMap tempCongloms; + private LongObjectHashMap tempCongloms; /** Next id to use for a temporary conglomerate. */ private static AtomicLong nextTempConglomId = new AtomicLong(-1); @@ -976,7 +975,7 @@ public long createConglomerate(String implementation, if ((temporaryFlag & TransactionController.IS_TEMPORARY) == TransactionController.IS_TEMPORARY) { if (this.tempCongloms == null) { - this.tempCongloms = new TLongObjectHashMap(); + this.tempCongloms = LongObjectHashMap.withExpectedSize(8); } this.tempCongloms.put(conglomId, conglom); } @@ -1090,14 +1089,10 @@ public String debugOpened() throws StandardException { } } if (this.tempCongloms != null) { - TLongObjectIterator iter = this.tempCongloms.iterator(); - while (iter.hasNext()) { - iter.advance(); - long key = iter.key(); - Object val = iter.value(); // A MemConglomerate object - sb.append("temp conglomerate id = ").append(key).append(": ").append( - val); - } + this.tempCongloms.forEachWhile((key, val) -> { + sb.append("temp conglomerate id = ").append(key).append(": ").append(val); + return true; + }); } } return sb.toString(); @@ -3816,7 +3811,7 @@ public long addAndLoadStreamContainer(final long segmentId, final long conglomId = getNextTempConglomId(); if (this.tempCongloms == null) { - this.tempCongloms = new TLongObjectHashMap(); + this.tempCongloms = LongObjectHashMap.withExpectedSize(8); } this.tempCongloms.put(conglomId, new FileStreamInputOutput(conglomId, this, rowSource, rwBuffer)); diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/ddl/GfxdDDLMessage.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/ddl/GfxdDDLMessage.java index b5ddfeffc..d1ce0680c 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/ddl/GfxdDDLMessage.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/ddl/GfxdDDLMessage.java @@ -38,8 +38,6 @@ import com.gemstone.gemfire.distributed.internal.ReplyMessage; import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember; import com.gemstone.gemfire.internal.InternalDataSerializer; -import com.gemstone.gnu.trove.TLongObjectHashMap; -import com.gemstone.gnu.trove.TLongProcedure; import com.pivotal.gemfirexd.internal.engine.GfxdConstants; import com.pivotal.gemfirexd.internal.engine.GfxdDataSerializable; import com.pivotal.gemfirexd.internal.engine.GfxdSerializable; @@ -60,6 +58,7 @@ import com.pivotal.gemfirexd.internal.impl.jdbc.EmbedConnection; import com.pivotal.gemfirexd.internal.impl.jdbc.EmbedStatement; import com.pivotal.gemfirexd.internal.shared.common.sanity.SanityManager; +import io.snappydata.collection.LongObjectHashMap; /** * {@link DistributionMessage} for sending GemFireXD DDL statements to members @@ -94,8 +93,8 @@ public final class GfxdDDLMessage extends GfxdMessage implements * The map of DDL statement IDs to the GfxdDDLMessage for the DDLs having * pending commit/rollback messages. */ - private static final TLongObjectHashMap pendingDDLMessages = - new TLongObjectHashMap(4); + private static final LongObjectHashMap pendingDDLMessages = + LongObjectHashMap.withExpectedSize(4); /** * MembershipListener to commit/rollback DDLs if node fails before sending @@ -446,7 +445,7 @@ protected void handleProcessorReplyException(String exPrefix, static GfxdDDLMessage removePendingDDLMessage(final long ddlId) { synchronized (pendingDDLMessages) { - return (GfxdDDLMessage)pendingDDLMessages.remove(ddlId); + return pendingDDLMessages.remove(ddlId); } } @@ -583,17 +582,12 @@ public void memberDeparted(final InternalDistributedMember member, final ArrayList memberPendingMessages = new ArrayList(4); synchronized (pendingDDLMessages) { - pendingDDLMessages.forEach(new TLongProcedure() { - @Override - public boolean execute(final long ddlId) { - final GfxdDDLMessage pendingMessage = - (GfxdDDLMessage)pendingDDLMessages.get(ddlId); - if (member.equals(pendingMessage.getSender())) { - memberPendingMessages.add(pendingMessage); - pendingDDLMessages.remove(ddlId); - } - return true; + pendingDDLMessages.forEachWhile((ddlId, pendingMessage) -> { + if (member.equals(pendingMessage.getSender())) { + memberPendingMessages.add(pendingMessage); + pendingDDLMessages.remove(ddlId); } + return true; }); } diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/distributed/GfxdConnectionWrapper.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/distributed/GfxdConnectionWrapper.java index 1115b524a..7d88141a9 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/distributed/GfxdConnectionWrapper.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/distributed/GfxdConnectionWrapper.java @@ -32,8 +32,7 @@ import com.gemstone.gemfire.internal.cache.TXStateInterface; import com.gemstone.gemfire.internal.util.ArrayUtils; import com.gemstone.gnu.trove.THashMap; -import com.gemstone.gnu.trove.TLongObjectHashMap; -import com.gemstone.gnu.trove.TLongObjectProcedure; +import com.koloboke.function.LongObjPredicate; import com.pivotal.gemfirexd.Attribute; import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserver; import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserverHolder; @@ -59,6 +58,7 @@ import com.pivotal.gemfirexd.internal.impl.sql.execute.ResultSetStatisticsVisitor; import com.pivotal.gemfirexd.internal.jdbc.InternalDriver; import com.pivotal.gemfirexd.internal.shared.common.sanity.SanityManager; +import io.snappydata.collection.LongObjectHashMap; /** * Wrapper class for Connections that provides for statement caching, convert to @@ -96,7 +96,7 @@ public final class GfxdConnectionWrapper { * statement which can happen when derby's statement cache also gets full. In * such a case the string shall be looked up from {@link #sqlMap}. */ - private final TLongObjectHashMap stmntMap; + private final LongObjectHashMap stmntMap; /** * Connection ID of the incoming request. @@ -117,7 +117,7 @@ public final class GfxdConnectionWrapper { private volatile boolean hasWaiters; /** map used when a statement is no longer available in {@link #stmntMap} */ - private final TLongObjectHashMap sqlMap; + private final LongObjectHashMap sqlMap; /** queue to clean weak EmbedStatement references from the map */ private final ReferenceQueue refQueue; @@ -137,8 +137,8 @@ public final class GfxdConnectionWrapper { final EmbedConnection conn = createConnection(defaultSchema, isRemote, isRemoteDDL, props); this.embedConn = conn; - this.stmntMap = new TLongObjectHashMap(); - this.sqlMap = new TLongObjectHashMap(); + this.stmntMap = LongObjectHashMap.withExpectedSize(8); + this.sqlMap = LongObjectHashMap.withExpectedSize(8); this.refQueue = new ReferenceQueue(); } else { @@ -716,7 +716,7 @@ private boolean clearStatementMap() { // Iterate over the map & close the statements // no need to synchronize since we expect only one thread to access // a connection at a time in any case - this.stmntMap.forEachEntry(collectStmts); + this.stmntMap.forEachWhile(collectStmts); stmts = collectStmts.stmts; this.stmntMap.clear(); } @@ -803,7 +803,7 @@ public final EmbedStatement getStatementForTEST(long statementID) { /** * Test API only -- NOT THREAD-SAFE. */ - public TLongObjectHashMap getStatementMapForTEST() { + public LongObjectHashMap getStatementMapForTEST() { return this.stmntMap; } @@ -1001,13 +1001,14 @@ public final void process(final EmbedConnection conn, } } - private static final class CollectStmts implements TLongObjectProcedure { + private static final class CollectStmts + implements LongObjPredicate { ArrayList stmts; @Override - public final boolean execute(final long id, Object stmt) { - stmt = ((StmntWeakReference)stmt).get(); + public boolean test(final long id, StmntWeakReference stmtRef) { + Object stmt = stmtRef.get(); if (stmt != null) { if (this.stmts == null) { this.stmts = new ArrayList(); @@ -1016,7 +1017,7 @@ public final boolean execute(final long id, Object stmt) { } return true; } - }; + } /** * This class will aid to clean up the statement map of WeakReference objects diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/distributed/ReferencedKeyCheckerMessage.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/distributed/ReferencedKeyCheckerMessage.java index 2e4b4678d..b3a0aa612 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/distributed/ReferencedKeyCheckerMessage.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/distributed/ReferencedKeyCheckerMessage.java @@ -32,6 +32,7 @@ import com.gemstone.gemfire.DataSerializer; import com.gemstone.gemfire.GemFireException; +import com.gemstone.gemfire.GemFireIOException; import com.gemstone.gemfire.SystemFailure; import com.gemstone.gemfire.cache.execute.EmptyRegionFunctionException; import com.gemstone.gemfire.cache.execute.FunctionException; @@ -60,8 +61,6 @@ import com.gemstone.gnu.trove.TIntHashSet; import com.gemstone.gnu.trove.TIntIntHashMap; import com.gemstone.gnu.trove.TIntIterator; -import com.gemstone.gnu.trove.TIntObjectHashMap; -import com.gemstone.gnu.trove.TIntObjectIterator; import com.gemstone.gnu.trove.TObjectObjectProcedure; import com.pivotal.gemfirexd.internal.engine.GfxdConstants; import com.pivotal.gemfirexd.internal.engine.Misc; @@ -93,6 +92,7 @@ import com.pivotal.gemfirexd.internal.impl.jdbc.EmbedConnection; import com.pivotal.gemfirexd.internal.impl.sql.execute.xplain.XPLAINUtil; import com.pivotal.gemfirexd.internal.shared.common.sanity.SanityManager; +import io.snappydata.collection.LongObjectHashMap; /** * This function is used to check the referenced key constraint after we @@ -131,9 +131,9 @@ public final class ReferencedKeyCheckerMessage extends private int[] refImpactedCols; private transient FormatableBitSet refColsUpdtdBits; private transient int [] refCol2DVDPosMapping; - private final transient TIntObjectHashMap refColUpdtd2DependentCols; + private final transient LongObjectHashMap refColUpdtd2DependentCols; private final transient TIntIntHashMap refCol2IndexMap; - private transient TIntObjectHashMap refColSameAfterModBitsMapping; + private transient LongObjectHashMap refColSameAfterModBitsMapping; private transient GfxdConnectionWrapper wrapperForMarkUnused; @@ -221,9 +221,9 @@ public ReferencedKeyCheckerMessage(final ReferencedKeyResultCollector rc, final ArrayList keyColumnValues, final ArrayList keyColumnLocations, final GemFireContainer[] refContainers, boolean forUpdate, int [] refImpactedCols, - FormatableBitSet refColsUpdtdBits, TIntObjectHashMap refColUpdtd2DependentCols, - TIntIntHashMap refCol2IndexMap, - int[] colToDVDPosMapping ) { + FormatableBitSet refColsUpdtdBits, + LongObjectHashMap refColUpdtd2DependentCols, + TIntIntHashMap refCol2IndexMap, int[] colToDVDPosMapping ) { super(rc, tx, getTimeStatsSettings(lcc), true); this.container = container; this.schemaName = container.getSchemaName(); @@ -587,8 +587,8 @@ public static void referencedKeyCheck(final GemFireContainer container, final ArrayList keyColumnValues, final ArrayList keyColumnLocations, boolean flushTXPendingOps, boolean forUpdate, int[] referencedImpactedCols,FormatableBitSet refColsUpdtdBits, - TIntObjectHashMap refColUpdtd2DependentCols, TIntIntHashMap refCol2IndexMap, - int[] colNumToDVDMapping) + LongObjectHashMap refColUpdtd2DependentCols, + TIntIntHashMap refCol2IndexMap, int[] colNumToDVDMapping) throws StandardException { final GemFireContainer[] refContainers = container.getExtraTableInfo() .getReferencedContainers(); @@ -885,7 +885,7 @@ public void fromData(DataInput in) boolean refColSameAfterModFlag = in.readBoolean(); if (refColSameAfterModFlag) { int numElements = in.readInt(); - this.refColSameAfterModBitsMapping = new TIntObjectHashMap( + this.refColSameAfterModBitsMapping = LongObjectHashMap.withExpectedSize( numElements); int byteArraySize = FormatableBitSet .numBytesFromBits(this.refColsUpdtdBits.getNumBitsSet()); @@ -989,17 +989,17 @@ public void toData(final DataOutput out) throws IOException { if (this.refColSameAfterModBitsMapping != null) { out.writeBoolean(true); out.writeInt(this.refColSameAfterModBitsMapping.size()); - TIntObjectIterator iter = this.refColSameAfterModBitsMapping - .iterator(); - while (iter.hasNext()) { - iter.advance(); - int rowNum = iter.key(); - byte[] refColSameAfterUpdt = (byte[])iter.value(); - out.writeInt(rowNum); - for (byte b : refColSameAfterUpdt) { - out.writeByte(b); + this.refColSameAfterModBitsMapping.forEachWhile((rowNum, refColSameAfterUpdt) -> { + try { + out.writeInt((int)rowNum); + for (byte b : refColSameAfterUpdt) { + out.writeByte(b); + } + return true; + } catch (IOException ioe) { + throw new GemFireIOException(ioe.getMessage(), ioe); } - } + }); } else { out.writeBoolean(false); @@ -1121,7 +1121,8 @@ private void identifyUpdatedColsUnchangedAndColsToWrite( if (old.equals(modified)) { // set bit on to indicate no change if (this.refColSameAfterModBitsMapping == null) { - this.refColSameAfterModBitsMapping = new TIntObjectHashMap(); + this.refColSameAfterModBitsMapping = + LongObjectHashMap.withExpectedSize(8); } if (refColSameAfterUpdt == null) { int numCols = this.refColUpdtd2DependentCols.size(); @@ -1139,8 +1140,7 @@ private void identifyUpdatedColsUnchangedAndColsToWrite( else { // find all the dependent cols & set their bit on so that // data can be written for those cols - TIntHashSet dependentCols = (TIntHashSet)this.refColUpdtd2DependentCols - .get(colNum); + TIntHashSet dependentCols = this.refColUpdtd2DependentCols.get(colNum); TIntIterator ti = dependentCols.iterator(); while (ti.hasNext()) { diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/sql/catalog/ExtraTableInfo.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/sql/catalog/ExtraTableInfo.java index 1db3ab627..95d5a9172 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/sql/catalog/ExtraTableInfo.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/sql/catalog/ExtraTableInfo.java @@ -23,11 +23,9 @@ import java.util.List; import com.gemstone.gemfire.internal.cache.LocalRegion; -import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk; import com.gemstone.gemfire.internal.offheap.annotations.Unretained; -import com.gemstone.gemfire.pdx.internal.unsafe.UnsafeWrapper; import com.gemstone.gnu.trove.TIntArrayList; -import com.gemstone.gnu.trove.TIntObjectHashMap; +import com.koloboke.function.LongObjPredicate; import com.pivotal.gemfirexd.internal.catalog.DependableFinder; import com.pivotal.gemfirexd.internal.catalog.UUID; import com.pivotal.gemfirexd.internal.engine.Misc; @@ -55,6 +53,7 @@ import com.pivotal.gemfirexd.internal.iapi.sql.dictionary.TableDescriptor; import com.pivotal.gemfirexd.internal.iapi.store.raw.ContainerHandle; import com.pivotal.gemfirexd.internal.iapi.store.raw.ContainerKey; +import io.snappydata.collection.LongObjectHashMap; public final class ExtraTableInfo extends ExtraInfo implements Dependent { @@ -88,7 +87,7 @@ public final class ExtraTableInfo extends ExtraInfo implements Dependent { private HashMap refKeyColumns2IndexNumbers; - private TIntObjectHashMap autoGenColumns; + private LongObjectHashMap autoGenColumns; private HashMap autoGenColumnNames; @@ -328,7 +327,7 @@ private final void refreshAutoGenColumnInfo() { cd = cdl.elementAt(index); if (cd.isAutoincrement()) { if (this.autoGenColumns == null) { // user provided column indexes - this.autoGenColumns = new TIntObjectHashMap(); + this.autoGenColumns = LongObjectHashMap.withExpectedSize(4); this.autoGenColumnNames = new HashMap(); } this.autoGenColumns.put(cd.getPosition(), cd); @@ -467,12 +466,22 @@ public final ColumnDescriptor getAutoGeneratedColumn(final String name) { public final boolean isAutoGeneratedColumn(final int position) { return this.autoGenColumns != null - && this.autoGenColumns.containsKey(position); + && this.autoGenColumns.contains(position); } public final int[] getAutoGeneratedColumns() { if (this.autoGenColumns != null) { - return this.autoGenColumns.keys(); + final int[] keys = new int[this.autoGenColumns.size()]; + this.autoGenColumns.forEachWhile(new LongObjPredicate() { + private int index; + + @Override + public boolean test(long k, ColumnDescriptor cd) { + keys[index++] = (int)k; + return true; + } + }); + return keys; } return null; } diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/sql/execute/GemFireResultSet.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/sql/execute/GemFireResultSet.java index 144893354..c624b5716 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/sql/execute/GemFireResultSet.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/sql/execute/GemFireResultSet.java @@ -44,7 +44,7 @@ import com.gemstone.gemfire.internal.cache.TXState; import com.gemstone.gemfire.internal.cache.TXStateInterface; import com.gemstone.gemfire.internal.offheap.annotations.Unretained; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.pivotal.gemfirexd.internal.engine.GfxdConstants; import com.pivotal.gemfirexd.internal.engine.Misc; import com.pivotal.gemfirexd.internal.engine.access.index.GlobalRowLocation; diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/impl/sql/execute/CreateDiskStoreConstantAction.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/impl/sql/execute/CreateDiskStoreConstantAction.java index 864d9f6b9..ca243f1a7 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/impl/sql/execute/CreateDiskStoreConstantAction.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/impl/sql/execute/CreateDiskStoreConstantAction.java @@ -28,7 +28,7 @@ import com.gemstone.gemfire.cache.DiskAccessException; import com.gemstone.gemfire.cache.DiskStoreFactory; -import com.gemstone.gemfire.internal.shared.OpenHashSet; +import io.snappydata.collection.OpenHashSet; import com.pivotal.gemfirexd.internal.engine.GfxdConstants; import com.pivotal.gemfirexd.internal.engine.Misc; import com.pivotal.gemfirexd.internal.engine.access.GemFireTransaction; diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/impl/sql/execute/UpdateResultSet.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/impl/sql/execute/UpdateResultSet.java index 7c5fac30f..896f4ca7a 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/impl/sql/execute/UpdateResultSet.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/impl/sql/execute/UpdateResultSet.java @@ -53,7 +53,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more import com.gemstone.gemfire.internal.offheap.annotations.Unretained; import com.gemstone.gnu.trove.TIntHashSet; import com.gemstone.gnu.trove.TIntIntHashMap; -import com.gemstone.gnu.trove.TIntObjectHashMap; import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserver; import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserverHolder; import com.pivotal.gemfirexd.internal.engine.GfxdConstants; @@ -90,6 +89,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more import com.pivotal.gemfirexd.internal.iapi.types.RowLocation; import com.pivotal.gemfirexd.internal.iapi.util.ReuseFactory; import com.pivotal.gemfirexd.internal.impl.sql.execute.xplain.XPLAINUtil; +import io.snappydata.collection.LongObjectHashMap; /** @@ -159,7 +159,7 @@ public final class UpdateResultSet extends DMLWriteResultSet implements OffHeapR * of the modification list.In effect it is the intersection set of the modified columns * and the refColsImpacted. */ - private final TIntObjectHashMap refColUpdtd2DependentCols; + private final LongObjectHashMap refColUpdtd2DependentCols; protected final GemFireXDQueryObserver observer = GemFireXDQueryObserverHolder.getInstance(); @@ -314,9 +314,11 @@ public final class UpdateResultSet extends DMLWriteResultSet implements OffHeapR this.container = ((MemConglomerate)this.constants.heapSCOCI.getConglom()) .getGemFireContainer(); if (!this.container.isTemporaryContainer()) { - TIntObjectHashMap tempRefColUpdtd2DependentCols = new TIntObjectHashMap(); + LongObjectHashMap tempRefColUpdtd2DependentCols = + LongObjectHashMap.withExpectedSize(4); - Map refColsImpactedMap = this.getReferencedUpdateCols(tempRefColUpdtd2DependentCols); + Map refColsImpactedMap = + this.getReferencedUpdateCols(tempRefColUpdtd2DependentCols); if (refColsImpactedMap != null) { this.refColUpdtd2DependentCols = tempRefColUpdtd2DependentCols; @@ -366,8 +368,9 @@ public final class UpdateResultSet extends DMLWriteResultSet implements OffHeapR // GemStone changes END } - - private Map getReferencedUpdateCols(TIntObjectHashMap tempRefColUpdtd2DependentCols) { + + private Map getReferencedUpdateCols( + LongObjectHashMap tempRefColUpdtd2DependentCols) { int[] refKeyCols = this.container.getExtraTableInfo() .getReferencedKeyColumns(); // check if any of the modified cols is a ref key column of a diff --git a/gemfirexd/tools/src/dunit/java/com/pivotal/gemfirexd/distributed/DistributedLockDUnit.java b/gemfirexd/tools/src/dunit/java/com/pivotal/gemfirexd/distributed/DistributedLockDUnit.java index f9c0fd8f5..9f61d7747 100644 --- a/gemfirexd/tools/src/dunit/java/com/pivotal/gemfirexd/distributed/DistributedLockDUnit.java +++ b/gemfirexd/tools/src/dunit/java/com/pivotal/gemfirexd/distributed/DistributedLockDUnit.java @@ -35,13 +35,13 @@ import com.gemstone.gemfire.internal.cache.LocalRegion; import com.gemstone.gemfire.internal.cache.PartitionedRegion; import com.gemstone.gemfire.internal.cache.execute.InternalRegionFunctionContext; -import com.gemstone.gnu.trove.TIntObjectHashMap; import com.pivotal.gemfirexd.DistributedSQLTestBase; import com.pivotal.gemfirexd.internal.engine.Misc; import com.pivotal.gemfirexd.internal.engine.distributed.GfxdListResultCollector; import com.pivotal.gemfirexd.internal.engine.distributed.message.RegionExecutorMessage; import com.pivotal.gemfirexd.internal.engine.distributed.utils.GemFireXDUtils; import com.pivotal.gemfirexd.internal.engine.locks.GfxdDRWLockService; +import io.snappydata.collection.LongObjectHashMap; import io.snappydata.test.dunit.AsyncInvocation; import io.snappydata.test.dunit.SerializableCallable; import io.snappydata.test.dunit.SerializableRunnable; @@ -488,7 +488,8 @@ public void run() { int[][] arrays5 = (int[][])async4.getResult(); System.gc(); - TIntObjectHashMap allKeys = new TIntObjectHashMap(numKeysPerVM * 5); + LongObjectHashMap allKeys = LongObjectHashMap.withExpectedSize( + numKeysPerVM * 5); checkUniqueKeys(allKeys, arrays1, "currentVM"); checkUniqueKeys(allKeys, arrays2, getServerVM(1)); checkUniqueKeys(allKeys, arrays3, getServerVM(2)); @@ -601,7 +602,7 @@ public void run() { // --------------- End function message execution ----------------- } - private static void checkUniqueKeys(final TIntObjectHashMap allKeys, + private static void checkUniqueKeys(final LongObjectHashMap allKeys, final int[][] arrays, final Object vm) { Object oldVM; // check uniqueness of keys and also that each list is in ascending order diff --git a/gemfirexd/tools/src/dunit/java/com/pivotal/gemfirexd/internal/engine/distributed/PreparedStatementDUnit.java b/gemfirexd/tools/src/dunit/java/com/pivotal/gemfirexd/internal/engine/distributed/PreparedStatementDUnit.java index b4079a9c9..677acba9e 100644 --- a/gemfirexd/tools/src/dunit/java/com/pivotal/gemfirexd/internal/engine/distributed/PreparedStatementDUnit.java +++ b/gemfirexd/tools/src/dunit/java/com/pivotal/gemfirexd/internal/engine/distributed/PreparedStatementDUnit.java @@ -14,9 +14,6 @@ * permissions and limitations under the License. See accompanying * LICENSE file. */ -/** - * - */ package com.pivotal.gemfirexd.internal.engine.distributed; import java.io.DataInput; @@ -41,7 +38,6 @@ import com.gemstone.gemfire.cache.control.RebalanceFactory; import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; import com.gemstone.gemfire.internal.offheap.ByteSource; -import com.gemstone.gnu.trove.TLongObjectHashMap; import com.pivotal.gemfirexd.DistributedSQLTestBase; import com.pivotal.gemfirexd.TestUtil; import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserver; @@ -64,6 +60,7 @@ import com.pivotal.gemfirexd.internal.impl.sql.GenericParameter; import com.pivotal.gemfirexd.internal.impl.sql.GenericParameterValueSet; import com.pivotal.gemfirexd.internal.impl.sql.GenericPreparedStatement; +import io.snappydata.collection.LongObjectHashMap; import io.snappydata.test.dunit.SerializableCallable; import io.snappydata.test.dunit.SerializableRunnable; import io.snappydata.test.dunit.VM; @@ -2804,16 +2801,22 @@ public static int verifyWrapperSize(int expectedSize) throws SQLException { return 0; } - TLongObjectHashMap stmntMap = wrapper.getStatementMapForTEST(); + LongObjectHashMap stmntMap = + wrapper.getStatementMapForTEST(); // invoke a getStatement to force drain refQueue - final long[] allKeys = stmntMap.keys(); - if (allKeys.length > 0) { - EmbedConnection conn = wrapper.getConnectionForSynchronization(); - synchronized (conn.getConnectionSynchronization()) { - wrapper.getStatement(null, allKeys[0], true, false, false, false, - null, false, 0, 0); + final GfxdConnectionWrapper connWrapper = wrapper; + stmntMap.forEachWhile((key, stmtRef) -> { + try { + EmbedConnection conn = connWrapper.getConnectionForSynchronization(); + synchronized (conn.getConnectionSynchronization()) { + connWrapper.getStatement(null, key, true, false, false, false, + null, false, 0, 0); + } + return false; + } catch (SQLException sqle) { + throw new RuntimeException(sqle); } - } + }); mapSize = stmntMap.size(); if (mapSize <= expectedSize) { return mapSize; diff --git a/settings.gradle b/settings.gradle index 2926aede4..b917a7be7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,6 +25,7 @@ include 'gemfire-core' include 'gemfire-junit' // include 'gemfire-web' include 'gemfire-examples' +include ':snappydata-util' include ':snappydata-store-shared' include ':snappydata-store-prebuild' include ':snappydata-store-core' @@ -37,6 +38,7 @@ include ':snappydata-native' project(':gemfire-jgroups').projectDir = "$rootDir/lgpl/gemfire-jgroups" as File project(':gemfire-trove').projectDir = "$rootDir/lgpl/gemfire-trove" as File +project(':snappydata-util').projectDir = "$rootDir/snappy-util" as File project(':snappydata-store-shared').projectDir = "$rootDir/gemfirexd/shared" as File project(':snappydata-store-prebuild').projectDir = "$rootDir/gemfirexd/prebuild" as File project(':snappydata-store-core').projectDir = "$rootDir/gemfirexd/core" as File diff --git a/gemfire-util/build.gradle b/snappy-util/build.gradle similarity index 87% rename from gemfire-util/build.gradle rename to snappy-util/build.gradle index 22c9cb7bc..a2079f334 100644 --- a/gemfire-util/build.gradle +++ b/snappy-util/build.gradle @@ -27,4 +27,9 @@ dependencies { compile "com.koloboke:koloboke-impl-common-jdk8:${kolobokeVersion}" // for classes using koloboke annotations compileOnly "com.koloboke:koloboke-compile:${kolobokeCompileVersion}" + + compile project(subprojectBase + 'gemfire-shared') + compile project(subprojectBase + 'gemfire-trove') } + +archivesBaseName = 'snappydata-util' diff --git a/gemfire-util/src/main/java/io/snappydata/collection/IntObjectHashMap.java b/snappy-util/src/main/java/io/snappydata/collection/LongObjectHashMap.java similarity index 55% rename from gemfire-util/src/main/java/io/snappydata/collection/IntObjectHashMap.java rename to snappy-util/src/main/java/io/snappydata/collection/LongObjectHashMap.java index 53be02b99..d182abe3f 100644 --- a/gemfire-util/src/main/java/io/snappydata/collection/IntObjectHashMap.java +++ b/snappy-util/src/main/java/io/snappydata/collection/LongObjectHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 SnappyData, Inc. All rights reserved. + * Copyright (c) 2018 SnappyData, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You @@ -17,26 +17,29 @@ package io.snappydata.collection; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - import com.koloboke.compile.KolobokeMap; +import com.koloboke.function.LongObjPredicate; @KolobokeMap -public abstract class IntObjectHashMap { +public abstract class LongObjectHashMap { + + public static LongObjectHashMap withExpectedSize(int expectedSize) { + return new KolobokeLongObjectHashMap<>(expectedSize); + } + + public abstract V put(long key, V value); - public static IntObjectHashMap withExpectedSize(int expectedSize) { - return new KolobokeIntObjectHashMap<>(expectedSize); + public final void update(long key, V value) { + put(key, value); } - public abstract V put(int key, V value); + public abstract V get(long key); - public abstract V get(int key); + public abstract boolean contains(long key); - public abstract Collection values(); + public abstract V remove(long key); - public abstract Set> entrySet(); + public abstract boolean forEachWhile(LongObjPredicate predicate); public abstract int size(); diff --git a/gemfire-util/src/main/java/io/snappydata/collection/ObjectLongHashMap.java b/snappy-util/src/main/java/io/snappydata/collection/ObjectLongHashMap.java similarity index 86% rename from gemfire-util/src/main/java/io/snappydata/collection/ObjectLongHashMap.java rename to snappy-util/src/main/java/io/snappydata/collection/ObjectLongHashMap.java index cb3c0b487..0de3179ec 100644 --- a/gemfire-util/src/main/java/io/snappydata/collection/ObjectLongHashMap.java +++ b/snappy-util/src/main/java/io/snappydata/collection/ObjectLongHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 SnappyData, Inc. All rights reserved. + * Copyright (c) 2018 SnappyData, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You @@ -18,7 +18,7 @@ package io.snappydata.collection; import java.util.Map; -import java.util.Set; +import java.util.function.ObjLongConsumer; import com.koloboke.compile.KolobokeMap; @@ -32,7 +32,7 @@ public static ObjectLongHashMap withExpectedSize(int expectedSize) { public static ObjectLongHashMap from(Map map) { KolobokeObjectLongHashMap m = new KolobokeObjectLongHashMap<>(map.size()); for (Map.Entry entry : map.entrySet()) { - m.justPut(entry.getKey(), entry.getValue()); + m.put(entry.getKey(), entry.getValue()); } return m; } @@ -45,9 +45,7 @@ public static ObjectLongHashMap from(Map map) { public abstract long removeAsLong(K key); - public abstract Set keySet(); - - public abstract Set> entrySet(); + public abstract void forEach(ObjLongConsumer action); public abstract int size(); diff --git a/gemfire-util/src/main/java/io/snappydata/collection/ObjectObjectHashMap.java b/snappy-util/src/main/java/io/snappydata/collection/ObjectObjectHashMap.java similarity index 96% rename from gemfire-util/src/main/java/io/snappydata/collection/ObjectObjectHashMap.java rename to snappy-util/src/main/java/io/snappydata/collection/ObjectObjectHashMap.java index c768e011f..74a5fa128 100644 --- a/gemfire-util/src/main/java/io/snappydata/collection/ObjectObjectHashMap.java +++ b/snappy-util/src/main/java/io/snappydata/collection/ObjectObjectHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 SnappyData, Inc. All rights reserved. + * Copyright (c) 2018 SnappyData, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You diff --git a/gemfire-shared/src/main/java/com/gemstone/gemfire/internal/shared/OpenHashSet.java b/snappy-util/src/main/java/io/snappydata/collection/OpenHashSet.java similarity index 79% rename from gemfire-shared/src/main/java/com/gemstone/gemfire/internal/shared/OpenHashSet.java rename to snappy-util/src/main/java/io/snappydata/collection/OpenHashSet.java index 4ca8bfadb..8ecb1b2b5 100644 --- a/gemfire-shared/src/main/java/com/gemstone/gemfire/internal/shared/OpenHashSet.java +++ b/snappy-util/src/main/java/io/snappydata/collection/OpenHashSet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 SnappyData, Inc. All rights reserved. + * Copyright (c) 2018 SnappyData, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You @@ -14,19 +14,18 @@ * permissions and limitations under the License. See accompanying * LICENSE file. */ -package com.gemstone.gemfire.internal.shared; +package io.snappydata.collection; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; -import java.util.function.Function; +import java.util.function.Consumer; import com.gemstone.gemfire.internal.concurrent.MapCallback; import com.gemstone.gemfire.internal.concurrent.MapResult; -import com.gemstone.gemfire.internal.concurrent.THashParameters; -import com.gemstone.gnu.trove.TObjectHashingStrategy; +import com.gemstone.gemfire.internal.shared.ClientResolverUtils; /** * An optimized HashSet using open addressing with quadratic probing. @@ -47,7 +46,6 @@ public class OpenHashSet extends AbstractSet protected static final int MAX_CAPACITY = 1 << 30; protected final float loadFactor; - protected final TObjectHashingStrategy hashingStrategy; protected int size; protected int occupied; @@ -56,7 +54,7 @@ public class OpenHashSet extends AbstractSet protected int mask; protected Object[] data; - protected Function, Void> postRehashHook; + protected Consumer> postRehashHook; @SuppressWarnings("unused") public OpenHashSet() { @@ -64,22 +62,15 @@ public OpenHashSet() { } public OpenHashSet(int initialCapacity) { - this(initialCapacity, 0.7f, THashParameters.DEFAULT_HASHING); + this(initialCapacity, 0.7f); } public OpenHashSet(int initialCapacity, float loadFactor) { - this(initialCapacity, loadFactor, THashParameters.DEFAULT_HASHING); - } - - public OpenHashSet(int initialCapacity, float loadFactor, - TObjectHashingStrategy hashingStrategy) { final int capacity = nextPowerOf2(initialCapacity); this.loadFactor = loadFactor; this.growThreshold = (int)(loadFactor * capacity); this.mask = capacity - 1; this.data = new Object[capacity]; - this.hashingStrategy = hashingStrategy != null - ? hashingStrategy : THashParameters.DEFAULT_HASHING; } public OpenHashSet(Collection c) { @@ -87,12 +78,16 @@ public OpenHashSet(Collection c) { addAll(c); } - public static int keyHash(Object k, TObjectHashingStrategy hashingStrategy) { - return ClientResolverUtils.fastHashInt(hashingStrategy.computeHashCode(k)); + protected int keyHash(Object key) { + return ClientResolverUtils.fastHashInt(key != null ? key.hashCode() : 0); + } + + protected boolean keyEquals(Object mapKey, Object key) { + return mapKey.equals(key); } protected final int insertionIndex(final Object[] data, final Object key, - final int hash, final TObjectHashingStrategy hashingStrategy) { + final int hash) { final int mask = this.mask; int pos = hash & mask; // try to fill the REMOVED slot but only if it is a new insertion @@ -104,11 +99,11 @@ protected final int insertionIndex(final Object[] data, final Object key, if (mapKey != null) { if (mapKey == REMOVED) { removedPos = pos; - } else if (hashingStrategy.equals(mapKey, key)) { + } else if (keyEquals(mapKey, key)) { // return already present key position as negative return -pos - 1; } - // quadratic probing with position increase by 1, 2, 3, ... + // quadratic probing (increase delta) pos = (pos + delta) & mask; delta++; } else { @@ -137,14 +132,14 @@ protected boolean doRemove(final Object[] data, final int pos) { } protected final int index(final Object[] data, final Object key, - final int hash, final TObjectHashingStrategy hashingStrategy) { + final int hash) { final int mask = this.mask; int pos = hash & mask; int delta = 1; while (true) { final Object mapKey = data[pos]; if (mapKey != null) { - if (mapKey != REMOVED && hashingStrategy.equals(mapKey, key)) { + if (mapKey != REMOVED && keyEquals(mapKey, key)) { return pos; } else { // quadratic probing with position increase by 1, 2, 3, ... @@ -159,8 +154,7 @@ protected final int index(final Object[] data, final Object key, protected final Object create(final K key, final MapCallback creator, final C context, final P params, - final MapResult result, final int hash, - final TObjectHashingStrategy hashingStrategy) { + final MapResult result, final int hash) { final Object[] data = this.data; final int mask = this.mask; int pos = hash & mask; @@ -173,7 +167,7 @@ protected final Object create(final K key, if (mapKey != null) { if (mapKey == REMOVED) { removedPos = pos; - } else if (hashingStrategy.equals(mapKey, key)) { + } else if (keyEquals(mapKey, key)) { // return old key return mapKey; } @@ -200,14 +194,14 @@ protected final Object create(final K key, } } - public void setPostRehashHook(Function, Void> hook) { + public final void setPostRehashHook(Consumer> hook) { this.postRehashHook = hook; } public final Object addKey(final Object key, final boolean replace, - final int hash, final TObjectHashingStrategy hashingStrategy) { + final int hash) { final Object[] data = this.data; - final int pos = insertionIndex(data, key, hash, hashingStrategy); + final int pos = insertionIndex(data, key, hash); if (pos >= 0) { doInsert(data, key, pos); return null; @@ -222,23 +216,19 @@ public final Object addKey(final Object key, final boolean replace, } public final Object getKey(final Object key) { - final TObjectHashingStrategy hashingStrategy = this.hashingStrategy; final Object[] data = this.data; - final int pos = index(data, key, keyHash(key, hashingStrategy), - hashingStrategy); + final int pos = index(data, key, keyHash(key)); if (pos >= 0) return data[pos]; else return null; } public final Object removeKey(final Object key) { - final TObjectHashingStrategy hashingStrategy = this.hashingStrategy; - return removeKey(key, keyHash(key, hashingStrategy), hashingStrategy); + return removeKey(key, keyHash(key)); } - private Object removeKey(final Object key, final int hash, - final TObjectHashingStrategy hashingStrategy) { + private Object removeKey(final Object key, final int hash) { final Object[] data = this.data; - final int pos = index(data, key, hash, hashingStrategy); + final int pos = index(data, key, hash); if (pos >= 0) { final Object mapKey = data[pos]; doRemove(data, pos); @@ -250,16 +240,13 @@ private Object removeKey(final Object key, final int hash, } public boolean contains(Object key) { - final TObjectHashingStrategy hashingStrategy = this.hashingStrategy; - return index(data, key, keyHash(key, hashingStrategy), hashingStrategy) >= 0; + return index(data, key, keyHash(key)) >= 0; } @Override public boolean add(E key) { - final TObjectHashingStrategy hashingStrategy = this.hashingStrategy; final Object[] data = this.data; - final int pos = insertionIndex(data, key, keyHash(key, hashingStrategy), - hashingStrategy); + final int pos = insertionIndex(data, key, keyHash(key)); if (pos >= 0) { doInsert(data, key, pos); return true; @@ -270,9 +257,7 @@ public boolean add(E key) { @Override public boolean remove(Object key) { - final TObjectHashingStrategy hashingStrategy = this.hashingStrategy; - return removeKey(key, keyHash(key, hashingStrategy), - hashingStrategy) != null; + return removeKey(key, keyHash(key)) != null; } @SuppressWarnings("NullableProblems") @@ -290,10 +275,6 @@ public final int capacity() { return this.data.length; } - public final TObjectHashingStrategy getHashingStrategy() { - return this.hashingStrategy; - } - @Override public void clear() { final Object[] data = this.data; @@ -339,13 +320,12 @@ protected final void rehash(final int newCapacity) { final Object[] newData = new Object[newCapacity]; final int newMask = newCapacity - 1; - final TObjectHashingStrategy hashingStrategy = this.hashingStrategy; int oldPos = 0; while (oldPos < capacity) { final Object d = data[oldPos]; if (d != null && d != REMOVED) { - final int newHash = keyHash(d, hashingStrategy); + final int newHash = keyHash(d); int newPos = newHash & newMask; int delta = 1; // No need to check for equality here when we insert. @@ -370,11 +350,11 @@ protected final void rehash(final int newCapacity) { this.growThreshold = (int)(loadFactor * newCapacity); if (this.postRehashHook != null) { - this.postRehashHook.apply(this); + this.postRehashHook.accept(this); } } - protected static int checkCapacity(int capacity) { + public static int checkCapacity(int capacity) { if (capacity > 0 && capacity <= MAX_CAPACITY) { return capacity; } else if (capacity == 0) {