Package com.taobao.metamorphosis.server.store

Examples of com.taobao.metamorphosis.server.store.MessageStore


        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        this.processor.prepareTransaction(context, xid);
        assertSame(tx, this.processor.getTransaction(context, xid));

        // commit two phase
        this.processor.commitTransaction(context, xid, false);
        store.flush();
        assertEquals(Transaction.FINISHED_STATE, tx.getState());
        assertNull(context.getTransactions().get(xid));

        assertTrue(store.getSizeInBytes() > 0);
    }
View Full Code Here


        this.processor.beginTransaction(context, xid, 0);
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        this.processor.processPutCommand(new PutCommand("topic1", 2, "world".getBytes(), xid, 0, 1), context, null);
        MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        assertEquals(0, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);

        // prepare
        this.processor.prepareTransaction(context, xid);
        assertEquals(1, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);
        assertEquals(1, this.processor.getPreparedTransactions(context, null).length);
        assertEquals(0, this.processor.getPreparedTransactions(context, "unknown").length);
        assertSame(this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER)[0], this.processor
            .getTransaction(context, xid).getTransactionId());

        // close and reopen it
        this.tearDown();
        this.init(this.path);
        this.newProcessor();
        this.processor.recoverPreparedTransactions();

        assertEquals(1, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);
        assertEquals(1, this.processor.getPreparedTransactions(context, null).length);
        assertEquals(0, this.processor.getPreparedTransactions(context, "unknown").length);
        assertSame(this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER)[0], this.processor
            .getTransaction(context, xid).getTransactionId());
        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        // commit two phase
        this.processor.commitTransaction(context, xid, false);
        store.flush();
        assertEquals(0, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);
        assertNull(context.getTransactions().get(xid));

        store.flush();
        assertTrue(store.getSizeInBytes() > 0);

    }
View Full Code Here

        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        // rollback
        this.processor.rollbackTransaction(context, xid);
        store.flush();
        assertEquals(Transaction.FINISHED_STATE, tx.getState());
        assertNull(context.getTransactions().get(xid));
        store.flush();
        assertEquals(0, store.getSizeInBytes());
    }
View Full Code Here

        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        // prepare
        this.processor.prepareTransaction(context, xid);
        assertSame(tx, this.processor.getTransaction(context, xid));

        // rollback
        this.processor.rollbackTransaction(context, xid);
        store.flush();
        assertEquals(Transaction.FINISHED_STATE, tx.getState());
        assertNull(context.getTransactions().get(xid));

        assertEquals(0, store.getSizeInBytes());

        // close and reopen it
        this.tearDown();
        this.init(this.path);
        this.newProcessor();
        this.processor.recoverPreparedTransactions();

        // ȷ��prepareΪ��
        store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());
        assertEquals(0, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);
    }
View Full Code Here

        assertNotNull(tx);
        assertSame(xid, tx.getTransactionId());
        this.replay();

        this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
        store.flush();
        assertEquals(0, store.getSizeInBytes());

        // prepare
        this.processor.prepareTransaction(context, xid);
        assertSame(tx, this.processor.getTransaction(context, xid));
View Full Code Here

                final AtomicBoolean replayed = new AtomicBoolean(false);
                final AtomicInteger counter = new AtomicInteger();
                if (ids != null && !ids.isEmpty()) {
                    for (final Map.Entry<MessageStore, List<Long>> entry : ids.entrySet()) {
                        final MessageStore msgStore = entry.getKey();
                        final AddMsgLocation addedLocation = locations.get(msgStore.getDescription());
                        // û�������Ϣ����Ҫ�������
                        final List<Long> idList = entry.getValue();
                        final List<PutCommand> cmdList = putCmds.get(msgStore);
                        if (addedLocation == null) {
                            counter.incrementAndGet();
                            msgStore.append(idList, cmdList, new AppendCallback() {
                                @Override
                                public void appendComplete(final Location newLocation) {
                                    replayed.set(true);
                                    final int checksum =
                                            CheckSum.crc32(MessageUtils.makeMessageBuffer(idList, cmdList).array());
                                    locations.put(msgStore.getDescription(),
                                        new AddMsgLocation(newLocation.getOffset(), newLocation.getLength(), checksum,
                                            msgStore.getDescription()));
                                    counter.decrementAndGet();
                                }
                            });

                        }
                        else {
                            // �����ط�
                            counter.incrementAndGet();
                            msgStore.replayAppend(addedLocation.getOffset(), addedLocation.getLength(),
                                addedLocation.checksum, idList, cmdList, new AppendCallback() {
                                @Override
                                public void appendComplete(final Location newLocation) {
                                    // ����طŵ�ʱ�������λ�ã�����Ҫ����λ����Ϣ
                                    if (newLocation != null) {
                                        replayed.set(true);
                                        locations.put(msgStore.getDescription(),
                                            new AddMsgLocation(newLocation.getOffset(), newLocation.getLength(),
                                                addedLocation.checksum, addedLocation.storeDesc));
                                    }
                                    counter.decrementAndGet();
                                }
View Full Code Here

    private int appendMsg(final int number, final long offset, final TxCommand cmd, final DataFile dataFile)
            throws InvalidProtocolBufferException, IOException {
        final AppendMessageCommand appendCmd = AppendMessageCommand.parseFrom(cmd.getCmdContent());
        final PutCommand putCmd =
                (PutCommand) decoer.decode(IoBuffer.wrap(appendCmd.getPutCommand().toByteArray()), null);
        final MessageStore store = this.storeManager.getOrCreateMessageStore(putCmd.getTopic(), putCmd.getPartition());

        if (this.transactionStore.getInflyTx(putCmd.getTransactionId()) == null) {
            dataFile.increment();
        }
        this.transactionStore.addMessage(store, appendCmd.getMessageId(), putCmd, new JournalLocation(number, offset));
View Full Code Here

                new LinkedHashMap<String, JournalTransactionStore.AddMsgLocation>();

        final int count = msgIds.size();

        for (final Map.Entry<MessageStore, List<Long>> entry : msgIds.entrySet()) {
            final MessageStore msgStore = entry.getKey();
            final List<Long> ids = entry.getValue();
            final List<PutCommand> cmds = putCommands.get(msgStore);
            // Append message
            msgStore.append(ids, cmds, new AppendCallback() {

                @Override
                public void appendComplete(final Location location) {
                    // Calculate checksum
                    final int checkSum = CheckSum.crc32(MessageUtils.makeMessageBuffer(ids, cmds).array());
                    final String description = msgStore.getDescription();
                    // Store append location
                    synchronized (locations) {
                        locations.put(description, new AddMsgLocation(location.getOffset(), location.getLength(),
                            checkSum, description));
                        // �������
View Full Code Here


        public Map<MessageStore, List<Long>> getMsgIds() {
            final Map<MessageStore, List<Long>> rt = new LinkedHashMap<MessageStore, List<Long>>();
            for (final Map.Entry<MessageStore, Queue<TxOperation>> entry : this.operations.entrySet()) {
                final MessageStore store = entry.getKey();
                final Queue<TxOperation> opQueue = entry.getValue();
                final List<Long> ids = new ArrayList<Long>();
                rt.put(store, ids);
                for (final TxOperation to : opQueue) {
                    if (to.getType() == TxOperation.ADD_OP) {
View Full Code Here


        public Map<MessageStore, List<PutCommand>> getPutCommands() {
            final Map<MessageStore, List<PutCommand>> rt = new LinkedHashMap<MessageStore, List<PutCommand>>();
            for (final Map.Entry<MessageStore, Queue<TxOperation>> entry : this.operations.entrySet()) {
                final MessageStore store = entry.getKey();
                final Queue<TxOperation> opQueue = entry.getValue();
                final List<PutCommand> ids = new ArrayList<PutCommand>();
                rt.put(store, ids);
                for (final TxOperation to : opQueue) {
                    if (to.getType() == TxOperation.ADD_OP) {
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.server.store.MessageStore

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.