Package com.sleepycat.je.rep

Examples of com.sleepycat.je.rep.ReplicatedEnvironment


        Map<String, Object> attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
        BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(attributes);

        BDBConfigurationStore bdbConfigurationStore = (BDBConfigurationStore) node.getConfigurationStore();
        ReplicatedEnvironment environment = (ReplicatedEnvironment) bdbConfigurationStore.getEnvironmentFacade().getEnvironment();

        assertEquals("Unexpected node priority value before mutation", 1, environment.getRepMutableConfig().getNodePriority());
        assertFalse("Unexpected designated primary value before mutation", environment.getRepMutableConfig().getDesignatedPrimary());
        assertEquals("Unexpected electable group override value before mutation", 0, environment.getRepMutableConfig().getElectableGroupSizeOverride());

        node.setAttribute(BDBHAVirtualHostNode.PRIORITY, 1, 2);
        node.setAttribute(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, false, true);
        node.setAttribute(BDBHAVirtualHostNode.QUORUM_OVERRIDE, 0, 1);

        assertEquals("Unexpected node priority value after mutation", 2, environment.getRepMutableConfig().getNodePriority());
        assertTrue("Unexpected designated primary value after mutation", environment.getRepMutableConfig().getDesignatedPrimary());
        assertEquals("Unexpected electable group override value after mutation", 1, environment.getRepMutableConfig().getElectableGroupSizeOverride());

        assertNotNull("Join time should be set", node.getJoinTime());
        assertNotNull("Last known replication transaction idshould be set", node.getLastKnownReplicationTransactionId());
    }
View Full Code Here


        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setTransactional(true);
        envConfig.setDurability(Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY)));

        ReplicatedEnvironment intruder = null;
        try
        {
            intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
        }
        finally
        {
            intruder.close();
        }

        assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS));
    }
View Full Code Here

        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setTransactional(true);
        envConfig.setDurability(Durability.parse((String)nodeData.get(BDBHAVirtualHostNode.DURABILITY)));

        ReplicatedEnvironment intruder = null;
        try
        {
            intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
        }
        finally
        {
            if (intruder != null)
            {
                intruder.close();
            }
        }

        waitForAttributeChanged(_baseNodeRestUrl + NODE1, VirtualHostNode.STATE, State.ERRORED.name());
        waitForAttributeChanged(_baseNodeRestUrl + NODE3, VirtualHostNode.STATE, State.ERRORED.name());
View Full Code Here

        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setTransactional(true);
        envConfig.setDurability(new Durability(Durability.SyncPolicy.SYNC, Durability.SyncPolicy.WRITE_NO_SYNC, Durability.ReplicaAckPolicy.SIMPLE_MAJORITY));

        ReplicatedEnvironment intruder = null;
        try
        {
            intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
        }
        finally
        {
            if (intruder != null)
            {
                intruder.close();
            }
        }

        for (int port: _groupCreator.getBrokerPortNumbersForNodes())
        {
View Full Code Here

            // test whether JVM system settings were applied
            Environment env = store.getEnvironment();
            assertEquals("Unexpected number of cleaner threads", TEST_NUMBER_OF_THREADS, env.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
            assertEquals("Unexpected log file max", TEST_LOG_FILE_MAX, env.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));

            ReplicatedEnvironment repEnv = store.getReplicatedEnvironment();
            assertEquals("Unexpected number of elections primary retries", TEST_ELECTION_RETRIES,
                    repEnv.getConfig().getConfigParam(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES));
            assertEquals("Unexpected number of elections primary retries", TEST_ENV_CONSISTENCY_TIMEOUT,
                    repEnv.getConfig().getConfigParam(ReplicationConfig.ENV_CONSISTENCY_TIMEOUT));
        }
        finally
        {
            ApplicationRegistry.remove();
        }
View Full Code Here

        return repConfigManager.makeReplicationConfig();
    }

    /* Make an ReplicatedEnvironment handle for this RepImpl. */
    public ReplicatedEnvironment makeEnvironment() {
        return new ReplicatedEnvironment(getEnvironmentHome(),
                                         cloneRepConfig(),
                                         cloneConfig());
    }
View Full Code Here

        repConfig.setNodeHostPort(nodeHost);
        repConfig.setHelperHosts(helperHost);

        /* Exit if can't create a replicated Environment successfully. */
        StatusListener listener = new StatusListener();
        ReplicatedEnvironment repEnv = null;
        try {
            repEnv = new ReplicatedEnvironment(new File(envHome),
                                               repConfig,
                                               envConfig,
                                               null,
                                               QuorumPolicy.ALL);
            repEnv.setStateChangeListener(listener);
        } catch (Exception e) {
            System.err.println("Can't successfully initialize " +
                               nodeName + " because of " + e);
            System.exit(-1);
        }

        /* Wait until the node becomes active. */
        listener.awaitActiveState();

        if (repEnv.getState().isMaster()) {

            /*
             * If master, start a transaction as a way of ascertaining whether
             * all nodes are up. Since the ReplicaAckPolicy is ALL, the
             * transaction will only begin when all the nodes are available.
             */
            Transaction txn = repEnv.beginTransaction(null, null);
            txn.abort();

            /* Invoke the group shutdown API. */
            repEnv.shutdownGroup(timeout, TimeUnit.SECONDS);
        } else if (repEnv.getState().isReplica()) {
            for (long i = 0; i < timeout; i++) {
                try {

                    /*
                     * The replica will throw a GroupShutdownException if it
                     * has received and processed the group close command from
                     * the master.
                     */
                    repEnv.getState();
                    Thread.sleep(1000);
                } catch (GroupShutdownException e) {
                    break;
                }
            }
        }
       
        /* Shutdown the replica. */
        repEnv.close();
    }
View Full Code Here

            }
        }
    }

    private void run() {
        ReplicatedEnvironment repEnv = recover();
        repEnv.close();
    }
View Full Code Here

        repConfig.setNodeName(nodeName);
        int port = Integer.parseInt(RepParams.DEFAULT_PORT.getDefault());
        String hostName = host + ":" + port;
        repConfig.setNodeHostPort(hostName);
        repConfig.setHelperHosts(hostName);
        final ReplicatedEnvironment rep =
            RepInternal.createDetachedEnv(envHome, repConfig, envConfig);
        try {
            ReplicatedEnvironment.State state = rep.getState();
            if (state != ReplicatedEnvironment.State.DETACHED) {
                throw EnvironmentFailureException.unexpectedState
                    ("joinState=" + state);
            }

            EnvironmentImpl envImpl =
                DbInternal.getEnvironmentImpl(rep);
            VLSNIndex vlsnIndex =
                RepInternal.getRepImpl(rep).getVLSNIndex();
            if (forward) {
                startLsn = DbLsn.NULL_LSN;
            } else {
                startLsn = envImpl.getFileManager().getLastUsedLsn();
            }

            int readBufferSize =
                envImpl.getConfigManager().getInt
                (EnvironmentParams.LOG_ITERATOR_READ_SIZE);
            FeederReader feederReader = null;
            FeederSyncupReader backwardsReader = null;

            VLSN scanVLSN = startVLSN;
            if (startVLSN.equals(VLSN.NULL_VLSN)) {
                RepImpl repImpl = RepInternal.getRepImpl(rep);
                VLSNRange range = repImpl.getVLSNIndex().getRange();
                if (forward) {
                    scanVLSN = range.getFirst();
                } else {
                    scanVLSN = range.getLast();
                }
            }
            if (scanVLSN.equals(VLSN.NULL_VLSN)) {
                /* Give up, no VLSN entries in the index. */
                System.out.println("<DbPrintLog>");
                System.out.println("</DbPrintLog>");
                return;
            }

            if (forward) {
                feederReader = new FeederReader(envImpl, vlsnIndex, startLsn,
                                                readBufferSize,
                                                new NameIdPair("n0", 0));
                feederReader.initScan(scanVLSN);
            } else {
                backwardsReader = new FeederSyncupReader
                    (envImpl, vlsnIndex,
                     startLsn, readBufferSize,
                     new NameIdPair("n0", 0),
                     scanVLSN,
                     DbLsn.NULL_LSN);
            }

            OutputWireRecord record = null;
            System.out.println("<DbPrintLog>");
            long lastLsn = 0;
            do  {
                if (forward) {
                    record = feederReader.scanForwards(scanVLSN, 0);
                    scanVLSN = scanVLSN.getNext();
                    lastLsn = feederReader.getLastLsn();
                } else {
                    record = backwardsReader.scanBackwards(scanVLSN);
                    scanVLSN = scanVLSN.getPrev();
                    lastLsn = backwardsReader.getLastLsn();
                }
                if (record != null) {
                    System.out.println
                    ("lsn=" + DbLsn.getNoFormatString(lastLsn) + " " + record);
                }
            } while (record != null);

            System.out.println("</DbPrintLog>");
        } finally {
            rep.close();
        }
    }
View Full Code Here

        }

        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setTransactional(true);
        envConfig.setAllowCreate(createEnv);
        ReplicatedEnvironment repEnv =
            new ReplicatedEnvironment(envHome, repConfig, envConfig);
        RepNode repNode = RepInternal.getRepImpl(repEnv).getRepNode();

        System.err.println("Handle created:" + repEnv +
                           "  Node idling indefinitely...");
        try {
            while (true) {
                System.out.println(new Date() +
                                   " State:" + repEnv.getState() + " " +
                                   " VLSN range:" +
                                   repNode.getVLSNIndex().getRange() +
                                   repNode.dumpState());
                Thread.sleep(pollIntervalMs);
            }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.rep.ReplicatedEnvironment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.