try {
if (this.metaConfig.isClosedPartition(request.getTopic(), request.getPartition())) {
log.warn("Can not put message to partition " + request.getPartition() + " for topic="
+ request.getTopic() + ",it was closed");
if (cb != null) {
cb.putComplete(new BooleanCommand(HttpStatus.Forbidden, "Partition[" + partitionString
+ "] has been closed", request.getOpaque()));
}
return;
}
// ����Ƕ�̬��ӵ�topic����Ҫע�ᵽzk
this.brokerZooKeeper.registerTopicInZk(request.getTopic(), false);
// ���slaveû�����ӣ����Ϸ���ʧ�ܣ���ֹmaster�ظ���Ϣ����
if (!this.remotingClient.isConnected(this.slaveUrl)) {
this.statsManager.statsPutFailed(request.getTopic(), partitionString, 1);
cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError, "Slave is disconnected ", request
.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);
if (cb != null) {
cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError, e.getMessage(), request.getOpaque()));
}
}
}