Skip to content

Commit

Permalink
[IOTDB-4406] Failure strategy when trigger failed to fire
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelly authored Sep 15, 2022
1 parent c85d80e commit ca37376
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.trigger.enums.TriggerEvent;
import org.apache.iotdb.commons.trigger.enums.TriggerType;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
Expand Down Expand Up @@ -154,6 +152,8 @@
import org.apache.iotdb.db.qp.sql.IoTDBSqlParser.UriContext;
import org.apache.iotdb.db.qp.sql.IoTDBSqlParserBaseVisitor;
import org.apache.iotdb.db.qp.utils.DatetimeUtils;
import org.apache.iotdb.trigger.api.enums.TriggerEvent;
import org.apache.iotdb.trigger.api.enums.TriggerType;
import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
package org.apache.iotdb.db.mpp.plan.statement.metadata;

import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.trigger.enums.TriggerEvent;
import org.apache.iotdb.commons.trigger.enums.TriggerType;
import org.apache.iotdb.db.mpp.plan.analyze.QueryType;
import org.apache.iotdb.db.mpp.plan.constant.StatementType;
import org.apache.iotdb.db.mpp.plan.statement.IConfigStatement;
import org.apache.iotdb.db.mpp.plan.statement.Statement;
import org.apache.iotdb.db.mpp.plan.statement.StatementVisitor;
import org.apache.iotdb.trigger.api.enums.TriggerEvent;
import org.apache.iotdb.trigger.api.enums.TriggerType;

import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iotdb.trigger.api;

import org.apache.iotdb.trigger.api.enums.FailureStrategy;
import org.apache.iotdb.tsfile.write.record.Tablet;

public interface Trigger {
Expand Down Expand Up @@ -55,6 +56,16 @@ default void onDrop() throws Exception {}
*/
default void restore() throws Exception {}

/**
* Overrides this method to set the expected FailureStrategy, {@link FailureStrategy#OPTIMISTIC}
* is the default strategy.
*
* @return {@link FailureStrategy}
*/
default FailureStrategy getFailureStrategy() {
return FailureStrategy.OPTIMISTIC;
}

/**
* @param tablet see {@link Tablet} for detailed information of data structure. Data that is
* inserted will be constructed as a Tablet and you can define process logic with {@link
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.trigger.api.enums;

import org.apache.iotdb.trigger.api.Trigger;
import org.apache.iotdb.tsfile.write.record.Tablet;

/**
* Type of FailureStrategy indicates what will happen when a trigger failed to do {@link
* Trigger#fire(Tablet)}. The triggers will be fired sequentially before and after the insertion.
* For example: Trigger1(BEFORE_INSERT) -> Trigger2(BEFORE_INSERT) -> Insertion ->
* Trigger3(AFTER_INSERT) -> Trigger4(AFTER_INSERT)
*/
public enum FailureStrategy {
/**
* If this strategy were adopted, the failure of {@link Trigger#fire(Tablet)} of one Tablet would
* not have any influence on the triggers that have not been fired. The failure of this Trigger
* will be simply ignored.
*/
OPTIMISTIC,

/**
* If this strategy were adopted, the failure of {@link Trigger#fire(Tablet)} of one Tablet would
* throw an exception and end this insertion. If a PESSIMISTIC trigger whose TRIGGER_EVENT is
* {@link TriggerEvent#BEFORE_INSERT} fails to fire in an insertion, all the triggers that have
* not fired will not be fired in this insertion and this insertion will not be executed. if a
* PESSIMISTIC trigger whose TRIGGER_EVENT is {@link TriggerEvent#AFTER_INSERT} fails to fire in
* an insertion, all the triggers that have not fired will not be fired, and this insertion will
* be marked as failed even if the insertion itself executed successfully.
*/
PESSIMISTIC,
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iotdb.commons.trigger.enums;
package org.apache.iotdb.trigger.api.enums;

public enum TriggerEvent {
BEFORE_INSERT((byte) 0, "BEFORE_INSERT"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iotdb.commons.trigger.enums;
package org.apache.iotdb.trigger.api.enums;

public enum TriggerType {
STATEFUL((byte) 0, "STATEFUL"),
Expand Down

0 comments on commit ca37376

Please sign in to comment.