Common Fault Tolerance: failover, failfast, failback, failsafe

1.failover: failover
meaning Fail-Over as "failover" is a backup mode of operation, when the main component exception that functions to the backup components. The point is that there is a main apparatus, and when a major fault backup enable, and set as the master. The dual Mysql Master mode, when in use fails Master, Master can take shots prepared using

2.failfast: Quick fail
to see is the "fail-fast" from the literal meaning, found errors in the system as much as possible, so that the system can be pre-configured in accordance with the process execution error, the corresponding mode is "fault-tolerant (fault tolerance ). " With JAVA collection (Collection) fast failure, for example, when multiple threads are operating on the same set of content, it may generate fail-fast event. For example: When a thread A iterator to traverse through a collection process, the content if the set is changed by the other thread; then thread A collection of access, ConcurrentModificationException will throw an exception (error found a good set execution error process), resulting in fail-fast event.

3.failback: failure automatic recovery
automatic recovery after Fail-over, in a cluster network system (there are two or more servers interconnected networks), due to a server maintenance, network resources and services needed to temporarily redirect backup system. After that the network resources and server recovery process by providing the original host, called automatic recovery

4.failsafe: Fail-safe
Fail-Safe is the meaning of "fail-safe", it will not cause harm even in case of failure or minimize damage. Examples of an image of the traffic lights on Wikipedia is "conflict monitoring module" will be the crossroads of traffic lights to flashing mode when the error signal detected an error or conflict when, instead of displaying all green.


----------------
Disclaimer: This article is CSDN blogger "herring into the clouds" of the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and link this statement.
Original link: https: //blog.csdn.net/u011305680/article/details/79730646

 

failfast (fast fault):

If a fault occurs, the error immediately.
Commonly used in non-idempotent operations, such as: single operation, if the write fails, the error immediately, do not have to try again.

 

failsafe (fail-safe):

If a failure occurs, it can be ignored, because this failure will not cause loss or damage within the acceptable range.
It is generally used to assist operations, such as: monitoring write log, if the write fault is ignored.

 

failover (failover):

If a failure occurs, the retry the backup mode.

Idempotent operations typically used, such as: MySql dual Master mode, if the primary Master failure, switching to the Master.
Retry will usually lead to more delay.

 

failback (recovery):

After failover, the primary modes of operation is restored, the primary modes of operation automatically restored from the backup mode of operation.

Such as: MySql dual mode Master, Master if the primary fails, the failover to the Master; Master when the primary recovery, is automatically switched to the main Master.

----------------
Disclaimer: This article is CSDN blogger "hanchao5272 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/hanchao5272/article/details/96439552

 

 

Fast fault and fail-safe systems Description:

If the system is shut down immediately when an error occurs, it is called fail-fast system . These systems will not continue error. When the system fails, they will stop running immediately. Rapid fault system errors will be exposed immediately. However, the fail-safe system is not the case. Even if the system fails, they will not stop running. They continue to operate by hiding the error. They will not expose errors immediately. They continue to error. Which system is the best system, the system design is always the most discussed topic in the field. In this article, we will discuss the limit of java Fail Fast and Safe Iterators Fail .

The Java Quick failures and safety failures iterators:

Java iteration allows us to traverse the Collection object. Iterator return a collection of nature is on the   fast failure on or inherently fail-safe of. If you made some changes in the collection of iterations, the fail-fast iterators would immediately lead to   a ConcurrentModificationException . In the fail-safe iterator, if it was modified during iteration of the iterative collection is no exception is thrown. Because they operate on a collection of clones, without the actual set of operations. Let's learn more about the fault fast iterators and fail-safe iterators.

The Java Fail-fast iterators:

Most types of collection returned Fail-Fast iterator when iterating collection, collection was not tolerated any structural modifications. (Structural modifications meant to add, delete, or update the elements in the collection) if the collection is structured modified in an iterative process, it will throw   a ConcurrentModificationException . However, if the collection is the iterator's own method (such as remove ()) modified, they will not throw any exceptions .

How fast iterators work?

All types Collection maintains an internal array of objects (Object []) to store the element. Fail fast iterators get directly from the array elements. They always think that this will not modify its internal array while iterating internal elements. In order to know whether the collection is modified, they used a called modCount internal flag, the flag will be updated every time the collection changes. Whenever the call Iterator next () when the method, it checks modCount . If after creating this iterator found modCount  has been updated, it throws   a ConcurrentModificationException .

The ArrayList , the Vector , the HashMap other iterator returned essentially on all   the Fail-Fast .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 years
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.ArrayList;
import java.util.Iterator;
 
public class FailFastIteratorExample
{      
     public static void main(String[] args)
     {
         //Creating an ArrayList of integers
         
         ArrayList<Integer> list = new ArrayList<Integer>();
         
         //Adding elements to list
         
         list.add( 1452 );
         
         list.add( 6854 );
         
         list.add( 8741 );
         
         list.add( 6542 );
         
         list.add( 3845 );
         
         //Getting an Iterator from list
         
         Iterator<Integer> it = list.iterator();
         
         while (it.hasNext())
         {
             Integer integer = (Integer) it.next();
             
             list.add( 8457 );      //This will throw ConcurrentModificationException
         }
     }  
}
Output:
1
2
3
4
Exception in thread "main" java.util.ConcurrentModificationException
     at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
     at java.util.ArrayList$Itr.next(Unknown Source)
     at pack1.MainClass.main(MainClass.java: 32 )

The fail-safe Java iterators:

如果在迭代集合时对其进行了修改,则故障保护迭代器不会引发任何异常。因为,它们迭代集合的克隆而不是实际集合。因此,这些迭代器不会注意到对实际集合进行的任何结构修改。但是,这些迭代器有一些缺点。其中之一是,并不总是保证您在迭代时会获得最新数据。因为创建迭代器后对集合的任何修改都不会在迭代器中更新。这些迭代器的另一个缺点是,就时间和内存而言,创建集合副本的开销会更大。

ConcurrentHashMap返回的迭代器是故障安全的迭代器。

1个
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18岁
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
 
public class FailSafeIteratorExample
{      
     public static void main(String[] args)
     {
         //Creating a ConcurrentHashMap
         
         ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<String, Integer>();
         
         //Adding elements to map
         
         map.put( "ONE" , 1 );
         
         map.put( "TWO" , 2 );
 
         map.put( "THREE" , 3 );
         
         map.put( "FOUR" , 4 );
         
         //Getting an Iterator from map
         
         Iterator<String> it = map.keySet().iterator();
         
         while (it.hasNext())
         {
             String key = (String) it.next();
             
             System.out.println(key+ " : " +map.get(key));
             
             map.put( "FIVE" , 5 );     //This will not be reflected in the Iterator
         }
     }  
}

输出:

二:
二四:四
一:
三:3

快速失败与Java中的失败安全迭代器:

失败快速迭代器 故障安全迭代器
失败快速迭代器不允许在对集合进行迭代时对其进行修改。 故障保护迭代器允许在对集合进行迭代时对其进行修改。
如果在迭代集合时对其进行了修改,则这些迭代器将引发ConcurrentModificationException 如果在迭代集合时对其进行了修改,则这些迭代器不会引发任何异常。
他们使用原始集合遍历集合的元素。 他们使用原始集合的副本遍历集合的元素。
这些迭代器不需要额外的内存。 这些迭代器需要额外的内存来克隆集合。
例如:ArrayListVectorHashMap返回的迭代器 例如:ConcurrentHashMap返回的迭代器

Guess you like

Origin www.cnblogs.com/maji233/p/11770416.html