Package com.taobao.metamorphosis.server.store

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


        // ��������
        for (int i = 0; i < 20000; i++) {
            // ��5����������Ϊ��
            final int partition = i % 4;
            final int step = i;
            final MessageStore store = metaBroker.getStoreManager().getOrCreateMessageStore(topic, partition);
            final long msgId = idWorker.nextId();
            store.append(msgId, new PutCommand(topic, partition, data, null, 0, 0), new AppendCallback() {

                @Override
                public void appendComplete(final Location location) {
                    // �������1044����Ϊlocation��offset��������Ϣ�����
                    allMsgs.add(new MessageInfo(msgId, location.getOffset() + 1044, partition));
                }
            });
            store.flush();
        }
        // ��������Ϣ�����ѡ��20��
        final List<MessageInfo> offsetInfos = new ArrayList<SamsaMasterBrokerUnitTest.MessageInfo>();
        for (int i = 0; i < 20; i++) {
            offsetInfos.add(allMsgs.get(random.nextInt(allMsgs.size())));
View Full Code Here


        final int flag = MessageFlagUtils.getFlag(null);
        final PutCommand request =
                new PutCommand(this.topic, partition, data, flag, CheckSum.crc32(data), null, opaque);
        final long msgId = 100000L;
        EasyMock.expect(this.remotingClient.isConnected(this.slaveUrl)).andReturn(true);
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.idWorker.nextId()).andReturn(msgId);
        EasyMock.expect(this.storeManager.getOrCreateMessageStore(this.topic, partition)).andReturn(store);
        final BooleanCommand expectResp =
                new BooleanCommand(HttpStatus.Success, msgId + " " + partition + " " + offset, opaque);
        final AtomicBoolean invoked = new AtomicBoolean(false);
        final PutCallback cb = new PutCallback() {

            @Override
            public void putComplete(final ResponseCommand resp) {
                invoked.set(true);
                if (!expectResp.equals(resp)) {
                    throw new RuntimeException();
                }
            }
        };
        final SamsaCommandProcessor.SyncAppendCallback apdcb =
                this.commandProcessor.new SyncAppendCallback(partition,
                    this.metaConfig.getBrokerId() + "-" + partition, request, msgId, cb);
        store.append(msgId, request, apdcb);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
                ((SamsaCommandProcessor.SyncAppendCallback) EasyMock.getCurrentArguments()[2]).appendComplete(Location
View Full Code Here

        final int flag = MessageFlagUtils.getFlag(null);
        final PutCommand request =
                new PutCommand(this.topic, partition, data, flag, CheckSum.crc32(data), null, opaque);
        final long msgId = 100000L;
        EasyMock.expect(this.remotingClient.isConnected(this.slaveUrl)).andReturn(true);
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.idWorker.nextId()).andReturn(msgId);
        EasyMock.expect(this.storeManager.getOrCreateMessageStore(this.topic, partition)).andReturn(store);
        final BooleanCommand expectResp =
                new BooleanCommand(
                    HttpStatus.InternalServerError,
                    "Put message to [slave 'meta://localhost:8124'] [partition 'SamsaCommandProcessorUnitTest-1'] failed",
                    opaque);
        final AtomicBoolean invoked = new AtomicBoolean(false);
        final PutCallback cb = new PutCallback() {

            @Override
            public void putComplete(final ResponseCommand resp) {
                invoked.set(true);
                System.out.println(((BooleanCommand) resp).getErrorMsg());
                if (!expectResp.equals(resp)) {
                    throw new RuntimeException();
                }
            }
        };
        final SamsaCommandProcessor.SyncAppendCallback apdcb =
                this.commandProcessor.new SyncAppendCallback(partition,
                    this.metaConfig.getBrokerId() + "-" + partition, request, msgId, cb);
        store.append(msgId, request, apdcb);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
                ((SamsaCommandProcessor.SyncAppendCallback) EasyMock.getCurrentArguments()[2]).appendComplete(Location
View Full Code Here

        final int flag = MessageFlagUtils.getFlag(null);
        final PutCommand request =
                new PutCommand(this.topic, partition, data, flag, CheckSum.crc32(data), null, opaque);
        final long msgId = 100000L;
        EasyMock.expect(this.remotingClient.isConnected(this.slaveUrl)).andReturn(true);
        final MessageStore store = this.mocksControl.createMock(MessageStore.class);
        EasyMock.expect(this.idWorker.nextId()).andReturn(msgId);
        EasyMock.expect(this.storeManager.getOrCreateMessageStore(this.topic, partition)).andReturn(store);
        final BooleanCommand expectResp =
                new BooleanCommand(
                    HttpStatus.InternalServerError,
                    "Put message to [master 'meta://localhost:8123'] [partition 'SamsaCommandProcessorUnitTest-1'] failed",
                    opaque);
        final AtomicBoolean invoked = new AtomicBoolean(false);
        final PutCallback cb = new PutCallback() {

            @Override
            public void putComplete(final ResponseCommand resp) {
                invoked.set(true);
                System.out.println(((BooleanCommand) resp).getErrorMsg());
                if (!expectResp.equals(resp)) {
                    throw new RuntimeException();
                }
            }
        };
        final SamsaCommandProcessor.SyncAppendCallback apdcb =
                this.commandProcessor.new SyncAppendCallback(partition,
                    this.metaConfig.getBrokerId() + "-" + partition, request, msgId, cb);
        store.append(msgId, request, apdcb);
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
                ((SamsaCommandProcessor.SyncAppendCallback) EasyMock.getCurrentArguments()[2]).appendComplete(Location
View Full Code Here

    @Override
    public TopicPartitionRegInfo load(final String topic, final String group, final Partition partition) {
        // �ȴӱ��ز�ѯ
        final MessageStoreManager storeManager = this.broker.getStoreManager();
        final MessageStore messageStore = storeManager.getMessageStore(topic, partition.getPartition());
        if (messageStore != null) {
            log.info("load offset from local"
                    + String.format(offsetFormat, topic, group, partition.getPartition(), messageStore.getSizeInBytes()));
            return new TopicPartitionRegInfo(topic, partition, messageStore.getMinOffset()
                + messageStore.getSizeInBytes());
        }
        else {
            final String masterServerUrl = this.slaveZooKeeper.getMasterServerUrl();
            if (StringUtils.isBlank(masterServerUrl)) {
                throw new NullPointerException("masterServerUrl is empty");
View Full Code Here

                    cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError,
                        "Invalid partition for transaction command:" + partition, cmd.getOpaque()));
                }
                return;
            }
            final MessageStore store = this.storeManager.getOrCreateMessageStore(topic, partition);
            if (store == null) {
                this.statsManager.statsPutFailed(topic, partitionString, 1);
                if (cb != null) {
                    cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError,
                        "Could not get or create message store for topic=" + topic + ",partition=" + partition, cmd
View Full Code Here

                    .getOpaque()));
                return;
            }

            final int partition = this.getPartition(request);
            final MessageStore store = this.storeManager.getOrCreateMessageStore(request.getTopic(), partition);

            // �����store��ͬ������֤ͬһ�������ڵ���Ϣ����
            synchronized (store) {
                // idҲ��������
                final long messageId = this.idWorker.nextId();
                // ����callback
                final SyncAppendCallback syncCB =
                        new SyncAppendCallback(partition, partitionString, request, messageId, cb);
                // ����slave
                this.remotingClient.sendToGroup(this.slaveUrl,
                    new SyncCommand(request.getTopic(), partition, request.getData(), request.getFlag(), messageId,
                        request.getCheckSum(), OpaqueGenerator.getNextOpaque()), syncCB,
                        this.sendToSlaveTimeoutInMills, TimeUnit.MILLISECONDS);
                // д��master
                store.append(messageId, request, syncCB);
            }
        }
        catch (final Exception e) {
            this.statsManager.statsPutFailed(request.getTopic(), partitionString, 1);
            log.error("Put message failed", e);
View Full Code Here

        try {
            this.masterServerUrl = this.slaveZooKeeper.getMasterServerUrl();
            for (final Map.Entry<String, List<Partition>> each : partitionsForTopics.entrySet()) {
                for (final Partition partition : each.getValue()) {
                    final String topic = each.getKey();
                    final MessageStore messageStore =
                            this.broker.getStoreManager().getMessageStore(topic, partition.getPartition());
                    // ���ز�������Ϣ�ļ�
                    final StringBuilder logStr = new StringBuilder();
                    if (messageStore == null) {
                        logStr.append("Local file for topic=").append(topic).append(" is not exist,partition=")
View Full Code Here

            final String topic = entry.getKey();
            final ConcurrentHashMap<Integer/* partition */, MessageStore> subMap = entry.getValue();
            if (subMap != null) {
                for (final Map.Entry<Integer, MessageStore> subEntry : subMap.entrySet()) {
                    final int partition = subEntry.getKey();
                    final MessageStore store = subEntry.getValue();
                    this.append(sb, topic, "part", partition, "min_offset", store.getMinOffset(), "max_offset",
                        store.getMaxOffset());
                }
            }
        }
    }
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());

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

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

TOP

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

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.