Search in sources :

Example 16 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class DLockService method removeLockService.

protected static void removeLockService(DLockService service) {
    service.removeAllTokens();
    InternalDistributedSystem system = null;
    synchronized (services) {
        DLockService removedService = (DLockService) services.remove(service.getName());
        if (removedService == null) {
            // another thread beat us to the removal... return
            return;
        }
        if (removedService != service) {
            services.put(service.getName(), removedService);
        } else {
            service.getStats().incServices(-1);
        }
        system = removedService.getDistributionManager().getSystem();
    }
    // if disconnecting and this was the last service, cleanup!
    if (services.isEmpty() && system.isDisconnecting()) {
        // get rid of stats and thread group...
        synchronized (DLockService.class) {
            closeStats();
        }
    }
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 17 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class CacheServerImpl method start.

@Override
public synchronized void start() throws IOException {
    Assert.assertTrue(this.cache != null);
    this.serialNumber = createSerialNumber();
    if (DynamicRegionFactory.get().isOpen()) {
        // from servers to clients instead of invalidates.
        if (!this.notifyBySubscription) {
            logger.info(LocalizedMessage.create(LocalizedStrings.CacheServerImpl_FORCING_NOTIFYBYSUBSCRIPTION_TO_SUPPORT_DYNAMIC_REGIONS));
            this.notifyBySubscription = true;
        }
    }
    this.advisor = CacheServerAdvisor.createCacheServerAdvisor(this);
    this.loadMonitor = new LoadMonitor(loadProbe, maxConnections, loadPollInterval, FORCE_LOAD_UPDATE_FREQUENCY, advisor);
    List overflowAttributesList = new LinkedList();
    ClientSubscriptionConfig csc = this.getClientSubscriptionConfig();
    overflowAttributesList.add(0, csc.getEvictionPolicy());
    overflowAttributesList.add(1, valueOf(csc.getCapacity()));
    overflowAttributesList.add(2, valueOf(this.port));
    String diskStoreName = csc.getDiskStoreName();
    if (diskStoreName != null) {
        overflowAttributesList.add(3, diskStoreName);
        // indicator to use diskstore
        overflowAttributesList.add(4, true);
    } else {
        overflowAttributesList.add(3, csc.getOverflowDirectory());
        overflowAttributesList.add(4, false);
    }
    this.acceptor = new AcceptorImpl(getPort(), getBindAddress(), getNotifyBySubscription(), getSocketBufferSize(), getMaximumTimeBetweenPings(), this.cache, getMaxConnections(), getMaxThreads(), getMaximumMessageCount(), getMessageTimeToLive(), this.loadMonitor, overflowAttributesList, this.isGatewayReceiver, this.gatewayTransportFilters, this.tcpNoDelay);
    this.acceptor.start();
    this.advisor.handshake();
    this.loadMonitor.start(new ServerLocation(getExternalAddress(), getPort()), acceptor.getStats());
    // TODO : Need to provide facility to enable/disable client health monitoring.
    // Creating ClientHealthMonitoring region.
    // Force initialization on current cache
    ClientHealthMonitoringRegion.getInstance(this.cache);
    this.cache.getLoggerI18n().config(LocalizedStrings.CacheServerImpl_CACHESERVER_CONFIGURATION___0, getConfig());
    /*
     * If the stopped bridge server is restarted, we'll need to re-register the client membership
     * listener. If the listener is already registered it won't be registered as would the case when
     * start() is invoked for the first time.
     */
    ClientMembershipListener[] membershipListeners = ClientMembership.getClientMembershipListeners();
    boolean membershipListenerRegistered = false;
    for (ClientMembershipListener membershipListener : membershipListeners) {
        // just checking by reference as the listener instance is final
        if (listener == membershipListener) {
            membershipListenerRegistered = true;
            break;
        }
    }
    if (!membershipListenerRegistered) {
        ClientMembership.registerClientMembershipListener(listener);
    }
    if (!isGatewayReceiver) {
        InternalDistributedSystem system = this.cache.getInternalDistributedSystem();
        system.handleResourceEvent(ResourceEvent.CACHE_SERVER_START, this);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LoadMonitor(org.apache.geode.cache.server.internal.LoadMonitor) LinkedList(java.util.LinkedList)

Example 18 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class LocalRegion method recursiveDestroyRegion.

/**
   * Removes entries and recursively destroys subregions.
   *
   * @param eventSet collects the events for all destroyed regions if null, then we're closing so
   *        don't send events to callbacks or destroy the disk region
   */
private void recursiveDestroyRegion(Set eventSet, RegionEventImpl regionEvent, boolean cacheWrite) throws CacheWriterException, TimeoutException {
    final boolean isClose = regionEvent.getOperation().isClose();
    // do the cacheWriter beforeRegionDestroy first to fix bug 47736
    if (eventSet != null && cacheWrite) {
        try {
            cacheWriteBeforeRegionDestroy(regionEvent);
        } catch (CancelException e) {
            // I don't think this should ever happens: bulletproofing for bug 39454
            if (!this.cache.forcedDisconnect()) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_RECURSIVEDESTROYREGION_PROBLEM_IN_CACHEWRITEBEFOREREGIONDESTROY), e);
            }
        }
    }
    if (this.eventTracker != null) {
        this.eventTracker.stop();
    }
    if (logger.isTraceEnabled(LogMarker.RVV) && getVersionVector() != null) {
        logger.trace(LogMarker.RVV, "version vector for {} is {}", getName(), getVersionVector().fullToString());
    }
    cancelTTLExpiryTask();
    cancelIdleExpiryTask();
    cancelAllEntryExpiryTasks();
    if (!isInternalRegion()) {
        getCachePerfStats().incRegions(-1);
    }
    this.cache.getInternalResourceManager(false).removeResourceListener(this);
    if (getMembershipAttributes().hasRequiredRoles()) {
        if (!isInternalRegion()) {
            getCachePerfStats().incReliableRegions(-1);
        }
    }
    // then the add only needs to be done if hasListener || hasAdminListener
    if (eventSet != null) {
        eventSet.add(regionEvent);
    }
    try {
        // call recursiveDestroyRegion on each subregion and remove it
        // from this subregion map
        Collection values = this.subregions.values();
        for (Iterator itr = values.iterator(); itr.hasNext(); ) {
            // element is a LocalRegion
            Object element = itr.next();
            LocalRegion region;
            try {
                LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
                try {
                    // converts to a LocalRegion
                    region = toRegion(element);
                } finally {
                    LocalRegion.setThreadInitLevelRequirement(LocalRegion.AFTER_INITIAL_IMAGE);
                }
            } catch (CancelException ignore) {
                // ignore, keep going through the motions though
                region = (LocalRegion) element;
            } catch (RegionDestroyedException ignore) {
                // SharedRegionData was destroyed
                continue;
            }
            // failed initialization removing it from the parent subregion map
            if (region.isDestroyed) {
                continue;
            }
            // BEGIN operating on subregion of this region (rgn)
            if (eventSet != null) {
                regionEvent = (RegionEventImpl) regionEvent.clone();
                regionEvent.region = region;
            }
            try {
                region.recursiveDestroyRegion(eventSet, regionEvent, cacheWrite);
                if (!region.isInternalRegion()) {
                    InternalDistributedSystem system = region.cache.getInternalDistributedSystem();
                    system.handleResourceEvent(ResourceEvent.REGION_REMOVE, region);
                }
            } catch (CancelException e) {
                // I don't think this should ever happen: bulletproofing for bug 39454
                if (!this.cache.forcedDisconnect()) {
                    logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_RECURSIVEDESTROYREGION_RECURSION_FAILED_DUE_TO_CACHE_CLOSURE_REGION_0, region.getFullPath()), e);
                }
            }
            // remove from this subregion map;
            itr.remove();
        // END operating on subregion of this region
        }
        try {
            if (this.indexManager != null) {
                try {
                    if (this instanceof BucketRegion) {
                        this.indexManager.removeBucketIndexes(getPartitionedRegion());
                    }
                    this.indexManager.destroy();
                } catch (QueryException e) {
                    throw new IndexMaintenanceException(e);
                }
            }
        } catch (CancelException e) {
            // I don't think this should ever happens: bulletproofing for bug 39454
            if (!this.cache.forcedDisconnect()) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_BASICDESTROYREGION_INDEX_REMOVAL_FAILED_DUE_TO_CACHE_CLOSURE_REGION_0, getFullPath()), e);
            }
        }
    } finally {
        // mark this region as destroyed.
        if (regionEvent.isReinitializing()) {
            this.reinitialized_old = true;
        }
        this.cache.setRegionByPath(getFullPath(), null);
        if (this.eventTracker != null) {
            this.eventTracker.stop();
        }
        if (this.diskRegion != null) {
            this.diskRegion.prepareForClose(this);
        }
        this.isDestroyed = true;
        // after isDestroyed is set to true call removeResourceListener to fix bug 49555
        this.cache.getInternalResourceManager(false).removeResourceListener(this);
        closeEntries();
        if (logger.isDebugEnabled()) {
            logger.debug("recursiveDestroyRegion: Region Destroyed: {}", getFullPath());
        }
        // otherwise, the listener will be closed after the destroy event
        try {
            postDestroyRegion(!isClose, regionEvent);
        } catch (CancelException e) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_RECURSIVEDESTROYREGION_POSTDESTROYREGION_FAILED_DUE_TO_CACHE_CLOSURE_REGION_0, getFullPath()), e);
        }
        // fix for bug #47061
        if (getServerProxy() == null) {
            closeCqs();
        }
        detachPool();
        if (eventSet != null) {
            closeCallbacksExceptListener();
        } else {
            closeAllCallbacks();
        }
        if (this.concurrencyChecksEnabled && this.dataPolicy.withReplication() && !this.cache.isClosed()) {
            this.cache.getTombstoneService().unscheduleTombstones(this);
        }
        if (this.hasOwnStats) {
            this.cachePerfStats.close();
        }
    }
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) Iterator(java.util.Iterator) Collection(java.util.Collection) StoredObject(org.apache.geode.internal.offheap.StoredObject) CancelException(org.apache.geode.CancelException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException)

Example 19 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class MultiRegionFunctionExecutor method executeFunction.

private ResultCollector executeFunction(final Function function, ResultCollector resultCollector) {
    InternalDistributedSystem ds = InternalDistributedSystem.getConnectedInstance();
    if (ds == null) {
        throw new IllegalStateException(LocalizedStrings.ExecuteFunction_DS_NOT_CREATED_OR_NOT_READY.toLocalizedString());
    }
    final DM dm = ds.getDistributionManager();
    final Map<InternalDistributedMember, Set<String>> memberToRegionMap = calculateMemberToRegionMap();
    final Set<InternalDistributedMember> dest = new HashSet<InternalDistributedMember>(memberToRegionMap.keySet());
    if (dest.isEmpty()) {
        throw new FunctionException(LocalizedStrings.MemberFunctionExecutor_NO_MEMBER_FOUND_FOR_EXECUTING_FUNCTION_0.toLocalizedString(function.getId()));
    }
    final InternalCache cache = GemFireCacheImpl.getInstance();
    if (function.optimizeForWrite() && cache != null && cache.getInternalResourceManager().getHeapMonitor().containsHeapCriticalMembers(dest) && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
        Set<InternalDistributedMember> hcm = cache.getResourceAdvisor().adviseCritialMembers();
        Set<DistributedMember> sm = SetUtils.intersection(hcm, dest);
        throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(function.getId(), sm), sm);
    }
    setExecutionNodes(dest);
    final InternalDistributedMember localVM = cache.getMyId();
    final LocalResultCollector<?, ?> localResultCollector = getLocalResultCollector(function, resultCollector);
    boolean remoteOnly = false;
    boolean localOnly = false;
    if (!dest.contains(localVM)) {
        remoteOnly = true;
    }
    if (dest.size() == 1 && dest.contains(localVM)) {
        localOnly = true;
    }
    validateExecution(function, dest);
    final MemberFunctionResultSender resultSender = new MemberFunctionResultSender(dm, localResultCollector, function, localOnly, remoteOnly, null);
    if (dest.contains(localVM)) {
        // if member is local VM
        dest.remove(localVM);
        Set<String> regionPathSet = memberToRegionMap.get(localVM);
        Set<Region> regions = new HashSet<Region>();
        if (regionPathSet != null) {
            InternalCache cache1 = GemFireCacheImpl.getInstance();
            for (String regionPath : regionPathSet) {
                regions.add(cache1.getRegion(regionPath));
            }
        }
        final FunctionContextImpl context = new MultiRegionFunctionContextImpl(function.getId(), getArgumentsForMember(localVM.getId()), resultSender, regions, this.isReExecute);
        boolean isTx = cache.getTxManager().getTXState() == null ? false : true;
        executeFunctionOnLocalNode(function, context, resultSender, dm, isTx);
    }
    if (!dest.isEmpty()) {
        HashMap<InternalDistributedMember, Object> memberArgs = new HashMap<InternalDistributedMember, Object>();
        for (InternalDistributedMember recip : dest) {
            memberArgs.put(recip, getArgumentsForMember(recip.getId()));
        }
        Assert.assertTrue(memberArgs.size() == dest.size());
        MultiRegionFunctionResultWaiter waiter = new MultiRegionFunctionResultWaiter(ds, localResultCollector, function, dest, memberArgs, resultSender, memberToRegionMap);
        return waiter.getFunctionResultFrom(dest, function, this);
    }
    return localResultCollector;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) DM(org.apache.geode.distributed.internal.DM) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LowMemoryException(org.apache.geode.cache.LowMemoryException) HashSet(java.util.HashSet) FunctionException(org.apache.geode.cache.execute.FunctionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 20 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class HandShake method handshakeWithServer.

/**
   * Client-side handshake with a Server
   */
public ServerQueueStatus handshakeWithServer(Connection conn, ServerLocation location, byte communicationMode) throws IOException, AuthenticationRequiredException, AuthenticationFailedException, ServerRefusedConnectionException {
    try {
        ServerQueueStatus serverQStatus = null;
        Socket sock = conn.getSocket();
        DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
        final InputStream in = sock.getInputStream();
        DataInputStream dis = new DataInputStream(in);
        DistributedMember member = getIDForSocket(sock);
        // if running in a loner system, use the new port number in the ID to
        // help differentiate from other clients
        DM dm = ((InternalDistributedSystem) this.system).getDistributionManager();
        InternalDistributedMember idm = dm.getDistributionManagerId();
        synchronized (idm) {
            if (idm.getPort() == 0 && dm instanceof LonerDistributionManager) {
                int port = sock.getLocalPort();
                ((LonerDistributionManager) dm).updateLonerPort(port);
                updateProxyID(dm.getDistributionManagerId());
            }
        }
        if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY) {
            this.credentials = getCredentials(member);
        }
        byte intermediateAcceptanceCode = write(dos, dis, communicationMode, REPLY_OK, this.clientReadTimeout, null, this.credentials, member, false);
        String authInit = this.system.getProperties().getProperty(SECURITY_CLIENT_AUTH_INIT);
        if (communicationMode != Acceptor.GATEWAY_TO_GATEWAY && intermediateAcceptanceCode != REPLY_AUTH_NOT_REQUIRED && (authInit != null && authInit.length() != 0)) {
            location.compareAndSetRequiresCredentials(true);
        }
        // Read the acceptance code
        byte acceptanceCode = dis.readByte();
        if (acceptanceCode == (byte) 21 && !(sock instanceof SSLSocket)) {
            // SSL
            throw new AuthenticationRequiredException(LocalizedStrings.HandShake_SERVER_EXPECTING_SSL_CONNECTION.toLocalizedString());
        }
        if (acceptanceCode == REPLY_SERVER_IS_LOCATOR) {
            throw new GemFireConfigException("Improperly configured client detected.  " + "Server at " + location + " is actually a locator.  Use addPoolLocator to configure locators.");
        }
        // Successful handshake for GATEWAY_TO_GATEWAY mode sets the peer version in connection
        if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && !(acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_REQUIRED || acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_FAILED)) {
            short wanSiteVersion = Version.readOrdinal(dis);
            conn.setWanSiteVersion(wanSiteVersion);
            // establish a versioned stream for the other site, if necessary
            if (wanSiteVersion < Version.CURRENT_ORDINAL) {
                dis = new VersionedDataInputStream(dis, Version.fromOrdinalOrCurrent(wanSiteVersion));
            }
        }
        // No need to check for return value since DataInputStream already throws
        // EOFException in case of EOF
        byte epType = dis.readByte();
        int qSize = dis.readInt();
        // Read the server member
        member = readServerMember(dis);
        serverQStatus = new ServerQueueStatus(epType, qSize, member);
        // Read the message (if any)
        readMessage(dis, dos, acceptanceCode, member);
        // DSes with different values of this. It shoule be a member variable.
        if (communicationMode != Acceptor.GATEWAY_TO_GATEWAY && currentClientVersion.compareTo(Version.GFE_61) >= 0) {
            deltaEnabledOnServer = dis.readBoolean();
        }
        // validate that the remote side has a different distributed system id.
        if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && Version.GFE_66.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_66) >= 0) {
            int remoteDistributedSystemId = in.read();
            int localDistributedSystemId = ((InternalDistributedSystem) system).getDistributionManager().getDistributedSystemId();
            if (localDistributedSystemId >= 0 && localDistributedSystemId == remoteDistributedSystemId) {
                throw new GatewayConfigurationException("Remote WAN site's distributed system id " + remoteDistributedSystemId + " matches this sites distributed system id " + localDistributedSystemId);
            }
        }
        // Read the PDX registry size from the remote size
        if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && Version.GFE_80.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_80) >= 0) {
            int remotePdxSize = dis.readInt();
            serverQStatus.setPdxSize(remotePdxSize);
        }
        return serverQStatus;
    } catch (IOException ex) {
        CancelCriterion stopper = this.system.getCancelCriterion();
        stopper.checkCancelInProgress(null);
        throw ex;
    }
}
Also used : GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) DataOutputStream(java.io.DataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SSLSocket(javax.net.ssl.SSLSocket) CancelCriterion(org.apache.geode.CancelCriterion) DM(org.apache.geode.distributed.internal.DM) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) IOException(java.io.IOException) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GemFireConfigException(org.apache.geode.GemFireConfigException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LonerDistributionManager(org.apache.geode.distributed.internal.LonerDistributionManager) SSLSocket(javax.net.ssl.SSLSocket) Socket(java.net.Socket) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream)

Aggregations

InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)209 Properties (java.util.Properties)70 Test (org.junit.Test)60 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)58 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)41 IOException (java.io.IOException)35 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)32 DM (org.apache.geode.distributed.internal.DM)30 File (java.io.File)22 HashSet (java.util.HashSet)21 Set (java.util.Set)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)19 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)19 Region (org.apache.geode.cache.Region)17 ArrayList (java.util.ArrayList)16 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)14 VM (org.apache.geode.test.dunit.VM)14 Cache (org.apache.geode.cache.Cache)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13