package com.ai.cloud.skywalking.reciever.storage;

import com.ai.cloud.skywalking.protocol.Span;
import com.ai.cloud.skywalking.reciever.selfexamination.ServerHealthCollector;
import com.ai.cloud.skywalking.reciever.selfexamination.ServerHeathReading;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;

public class Chain {
    private static Logger logger = LogManager
            .getLogger(Chain.class);

    private List<IStorageChain> chains;

    private int index = 0;

    public Chain(List<IStorageChain> chains) {
        this.chains = chains;
    }

    public void doChain(List<Span> spans) {
        if (index < chains.size()) {
            while (true) {
                try {
                    chains.get(index++).doChain(spans, this);
                    break;
                } catch (Throwable e) {
                    logger.error("do chain at index[{}] failure.", index, e);
                    ServerHealthCollector.getCurrentHeathReading("storage-chain").updateData(ServerHeathReading.ERROR,
                            "Failed to do chain action. spans list hash code:" + spans.hashCode() + ",Cause:" + e.getMessage());
                    // 如果Chain出现任何异常，将重做Chain,保证数据不丢失
                    index--;
                }
            }
        }

    }

    void addChain(IStorageChain chain) {
        chains.add(chain);
    }
}

@@ -927,10 +927,27 @@
 dex%5B
-%7B%7D
+%22 + (index - 1) + %22
 %5D fa
@@ -958,15 +958,8 @@
 e.%22,
- index,
  e);
@@ -1102,42 +1102,57 @@
     
-        %22Failed to do chain action
+%09%09%22do chain at index%5B%22 + (index - 1) + %22%5D failure
 . sp

修改一个日志不正确的问题。