Michel J De Souza
email: michel@dcc.ufba.br

Franc ¸oise Baude
email: francoise.baude@unice.fr

Distributed Snapshot algorithm for multi-active object-based applications

This paper exposes an adaptation of the classic algorithm for consistent snapshot in distributed systems with asynchronous processes due to Chandy&Lamport. A snapshot in this context is described as the consistent set of states of all involved communicating processes that allows recovering the whole system after a crash. The reconstructed system state is consistent, even if messages injected into the system from the outside while the snapshot was ongoing may have been lost (if such messages can not be replayed). We expose how to adapt this algorithm to a particular distributed programming model, the Active Object model (in its multi active version). We applied it successfully to a non trivial distributed application programmed using Active Objects serving as a publish/subscribe and storage of events middleware, dubbed the EventCloud.

Introduction

When a system is dealing with a huge amount of data, it is important to have a backup mechanism that allows its recovery in case of disaster, loss of energy, etc, which in the sequel, we assume requires recovering the whole system, not only one or a few processes. In practice, to accomplish this task a snapshot algorithm can be used to regularily take a consistent and global, even if distributed, checkpoint. A snapshot is indeed the process of collection of data that allows to create a global consistent image of the system state. This paper proposes a snapshot algorithm that works as an adapted version of the classic Chandy-Lamport algorithm [START_REF] Chandy | Distributed snapshots: Determining global states of distributed systems[END_REF]. The algorithm is adapted in order to suit the constraints from the use of the Active Object programming model that is used to program our distributed system dubbed the EventCloud. Its aim is to act as a storage of events, and allow end-users to retrieve them in an asynchronous manner thanks to a publish-subscribe model. The system is architectured along a structured peer-to-peer overlay network, and aims to be deployed on distributed physical infrastructures (private cluster, private/public cloud, etc.).

Snapshot algorithms assume initial input data is available and could be used ultimately to recover the execution from the very beginning if needed. On the contrary, in our case, input data is coming continuously from the outside, in the form of publications and subscriptions injected inside the EventCloud. It is not realistic to assume we can log all this exterrnal information (as the log would replicate the data that is eventually stored in the EventCloud). Consequently our solution can suffer of publications loss in some circumstances; however, we propose an ad-hoc solution for preventing subscriptions loss. This paper is organized as follows: the section 2 provides the background and some important concepts to understand the work proposed; the section 3 presents the solution in details and how to address the specificities due to the Active Object programming model as used to implement the EventCloud; the section 4 presents the way an Event-Cloud gets reconstructed out of a taken snapshot, and consequently which are the failure supported assumptions. The last section concludes and summarizes the improvements left as future works.

Background

The proposed snapshot algorithm is implemented within the EventCloud software using the ProActive middleware , thus offering both large-scale deployment capabilities of Active Objects on distributed infrastructures and remote communication features between these objects. This section describes the needed concepts.

Proactive

ProActive [INRIA and UNS 2000] is an open source Java library aiming to simplify the programming of multithreaded, parallel and distributed applications for clusters, grids, clouds, and any distributed infrastructure in general. Some ProActive features useful in the sequel are the following. Activities that can execute in parallel take the form of distributed, remotely accessible objects. An active object is an entity with its own configurable activity. Each active object has its own thread of control (so the term "active") that is in charge of selecting and serving the next method call, among those awaiting to be served. Requests to execute method calls are automatically stored in a queue of pending requests. Requests are sent in a FIFO manner on the communication channel connecting a caller and a callee. This FIFO behaviour happens because of a Rendez-Vous protocol: an acknowledgement from the callee is sent back to the caller, to commit the request is stored in the request queue waiting to be served in an asynchronous manner. Consequently, the caller can not initiate a second request before receiving this acknowledgment, ensuring FIFO placement of corresponding requests in the queue in case they target the same callee. By default, the serving policy of requests stored in a queue is FIFO, and one request is served by the control thread at a time. Eventually, active objects interact by asynchronous method calls. Results of method calls are called futures and are first class entities. Callers can transparently wait for results using a mechanism called wait-by-necessity [START_REF] Caromel | Toward a method of object-oriented concurrent programming[END_REF]]. A callee transparently updates the corresponding future of a method invocation, which automatically wakes up the awaiting caller if it is already blocked waiting for the result.

A distributed or concurrent application that uses ProActive is composed of several active objects. A recent ProActive version [START_REF] Henrio | Multi-threaded active objects[END_REF]] replaces active objects by multi-active objects, allowing to serve more than one request at a time. To accomplish this task, one can declare compatibility groups of methods. Requests marked as compatible are allowed to be served in parallel. The algorithm proposed in this work is implemented using the multi-active objects version.

EventCloud

As described in [START_REF] Baude | PLAY Deliverable D2.1 Requirements specification for Event Cloud Component[END_REF]], the EventCloud is a distributed store of data following the W3C RDF specification, that handles SPARQL queries across the distributed architecture. RDF is a fundamental part of the Semantic Web stack offering a graph structured data model where each relation is made by default of a triple (subject, predicate, object). Although RDF uses triples, the EventCloud works with quadruples -an extended version of a triple that adds a fourth element (usually named context or graph value) to indicate or to identify the data source. Events stored in the EventCloud module can be simple or compound. A compound event is made of a set of quadruples with each quadruple sharing the same graph value. This graph value is assumed to be an identifier that uniquely identifies a compound event.

The EventCloud is a module deployed over a CAN [START_REF] Ratnasamy | A scalable content-addressable network[END_REF]] structured peer-to-peer network (a D-dimensional space torus topology). Each peer is a multiactive object that can receive requests that are put into a request queue. All the non compatible requests (e.g. adding a peer reference as neighbour request, and routing a request towards are served in a FIFO (First-in, First-out) manner, whereas declared compatible ones can be served in parallel by the multi-active object (e.g. several requests to route a message whose purpose is relative to a publish or subscribe operation in a dataspace zone the peer is not responsible of can be handled in parallel: their treatment consists to forward the message further in the CAN, by sending it to the right neighbour). Each peer has also a handful of Jena datastores [Jena 2014] to store quadruples, intermediate query results, queries, etc. In the sequel, we will simplify by considering only one single datastore is attached to each peer.

The EventCloud works with the publisher-subscriber paradigm where any external user connected to the EventCloud through a proxy can subscribe to receive data that he is interested in, or can publish data. To make this possible, the EventCloud uses the SPARQL query language to formulate the subscriptions.

The EventCloud module integrates within the PLAY Platform described in [START_REF] Stühmer | PLAY Deliverable D1.4 Play Conceptual Architecture[END_REF]]. The PLAY Platform aims at creating an Event Marketplace at the Web scale. A marketplace works as a search engine dedicated to events and provides visibility to distributed sources of events.

Chandy-Lamport snapshot algorithm

Before starting to explain how the snapshot algorithm of [START_REF] Chandy | Distributed snapshots: Determining global states of distributed systems[END_REF] works, it is important to establish some concepts used by it:

• A distributed system consists of a finite set of processes with finite set of channels. It is described by a directed, labeled graph in which the vertices represent processes and the edges represent channels. • A channel is the connection between two processes by which messages can be sent. It is assumed to have infinite buffers, to be error-free and to deliver messages in the order sent. • The state of a channel is the sequence of messages sent along the channel, excluding the messages received along the channel. • A process is defined by a set of states: an initial one and a set of actions. An action a in a process p is an atomic action that may change p's state itself and the state from at most one channel c incident on p. • The communication in a distributed system happens by the exchange of messages.

A process only records its own state and the messages it sends and receives.

• To determine a global state, a process must count on the cooperation of the others processes composing the system. They must record their own local states and send this data to a chosen process charged of recording the collected data. • Unless relying upon a global common clock, the processes cannot record their local states precisely at the same instant.

• The global-state-taking algorithm (snapshot) must run concurrently with the underlying computation not altering it. • A global state for a distributed system is a set of process and channel states. The initial global state is one in which the state of each process is its initial state and the state of each channel is the empty sequence. The algorithm uses two basic procedures to control the global state construction process and can be initiated for one or more processes. The process in charge of initiating the snapshot algorithm taking records its state spontaneously without receiving a token from others processes. The procedure that represents the sending of a token is named Marker-Sending Rule. In this procedure, a process will initially record its state and then will send a token along each channel c directed away from itself. The procedure that represents the receiving of a token is named Marker-Receiving Rule. On receiving a token for the first time, a process will record its state (locally). Once a process receives the remaining tokens (from its neighbors), it needs to record the channel state by which the token has arrived. This state is composed by the messages that has arrived after the process has recorded its state and before the receiving of the token. Once the data is collected each process sends it to the process that has started the algorithm. The Figure 1 depicts the algorithm.

Snapshot algorithm for the EventCloud system based on Active Objects

Snapshot Manager

The Snapshot Manager regularly triggers the execution of the snapshot algorithm. If asked, it can initiate an EventCloud instance reconstruction by using the data collected, so it is working as a safe storage place receiving all the peer's data, etc. Reconstruction will be addressed in the next section.

The Snapshot Manager is a multi active object having a reference to an Event-Cloud Registry. The EventCloud Registry holds reference to EventCloud instances. In this way, whenever the Snapshot Manager needs to perform any operation (start a snapshot, restoration, etc) for one specific Event Cloud, it is going to contact the registry in order to obtain the reference that will allow to fulfill the task.

Snapshot algorithm adapted from Chandy-Lamport solution

As within Chandy-Lamport algorithm, in the adapted solution presented in this work, channels are assumed to be uni-directional, but between any two peers, a channel in both directions does exist. Moreover, there is a channel from a peer to itself, as a peer can send requests to itself. Differently from original version, each peer collects its data and sends it to the safe storage place; whereas in Chandy-lamport algorithm, the data collected is sent to the peer that has started the algorithm.

Peer data to be saved with the algorithm are as follows:

1. Jena datastore -application data. 2. Request queue relevant information. 3. Topology information: neighborhood table, zone, etc. 4. Some other EventCloud management parameters.

The Figure 2 above depicts our adapted snapshot taking algorithm. The black arrow (1) illustrates the moment when the Snapshot Manager initiates the snapshot process choosing randomly a peer to trigger the algorithm.

Once the chosen peer to trigger the algorithm receives the request, it records part of its state by sending its Jena datastore1 to the safe storage place (Snapshot Manager)this step is illustrated by the dashed black arrow (2). At this point, the peer locally copies part of the data it needs to collect -topology information (neighborhood table, zone, etc), in order to add this data to its corresponding saved state later on (see below).

Once this same peer has performed the tasks described above, it propagates the token towards its neighbors (including to itself). This step is described by the gray arrows (3). This ends up the operation named Marker sending rule of the Chandy Lamport algorithm (see Figure 1).

On the picture, a yellow arrow (4) describes a sending of a token from all the starter peer neighbors to it. This represents only the starter peer perspective. However, on receiving a token for the fist time, a peer will send a token to each one of its neighbors. Notice the figure only depicts the initiator peer algorithm execution, but it runs almost simarily on each peer (except regarding the black arrow).

Regarding our adaptation of the Marker receiving rule of the algorithm, the following is taken in consideration. The grey (3) or yellow arrows (4), the receiving of a token, trigger a key action: "closing the channel" they are sent onto.

Every peer, including the initiator one, will have to have served n+1 tokens in total (token carried in the form of a remote method invocation), to terminate the execution of the algorithm instance. One token from each of its n neighbors, and another one that it has sent to itself (as each peer might trigger a method call, i.e. send a request, to itself). Indeed, in the Active Object model, the active object can invoke methods on itself; in the EventCloud implementation, this is extensively used. This self-sent token closes a channel from it to itself. In general, each token served by a peer closes the channel directed from the corresponding sender peer to it. Notice that because each peer is an active object, it stores the received requests (messages) in its request queue. Consequently, we have to adapt the Chandy Lamport algorithm to the fact that channels are not easily identified: they are all mixed in each active object single request queue, and are materialized only at the receiving edge of the channel (i.e. if peer A can send a method call MC to peer B because A knows B' object reference, the unidirectional communication channel that connects A to B gets materialized by the fact that the message MC is stored in the request queue of peer B. Before MC gets served, one can consider that MC is still on the wire between A and B. This is why MC might need to be part of the global snapshot, besides the states recorded at the moment A and B respectively and independently serve their first token).Consequently, the operation to save in transit messages then close a channel once a token from a neighbour has arrived, has been carefully designed, as detailed just below.

One really important information of the global snapshot to be saved is the relevant (subpart of) request queue information of each peer; so, in background, always before the scheduler in charge of selecting which next request(s) can be served takes out a request from the peer queue, an evaluation process happens to decide if this request (the corresponding message) will be locally copied with all the other requests that represents the in-transit messages (these requests will be sent to the Snapshot Manager once the peer has finished its snapshot taking process). For a request to be saved, three properties need to be verified: the request cannot be a token because a token represents only a control request part of the algorithm managing what needs to be saved; the peer that has received the request needs to be in RUNNING state what implies the peer being active from the snapshot taking algorithm viewpoint and indicates it hasn't yet finished it's data collection of the current snapshot algorithm instance; at last, the directed channel from the peer sender to peer receiver needs to be still open. The reception of a token on a channel closes this channel. Hence, if a peer has sent a token to another peer and after generates new requests to this same peer they won't be saved at receiver side because they have arrived after the token that closed the channel (a strong property of the active object model is that communication between any two objects is FIFO). On the contrary, if a peer has sent a token to a neighbour, but has not received a token from it, any received request originating from this neighbour is to be considered in transit. So it is going to be part of the corresponding channel state in the global snapshot.

At last, having received all the needed tokens, the peer will send the data it locally collected to the Snapshot Manager, thus enriching the peer state that was only partly recorded so far. This data is composed by the relevant request queue information saved during the moment at which the peer gets engaged in the algorithm snapshot (it has received the first token) and the moment it finishes (it has received all the tokens) and the topology information copied previously. This step is described by the red arrow (5).

The picture above depicts the snapshot algorithm from only one peer perspective. However, after the other peers have received the token, they will execute the same set of actions (symmetrically): save its state, send a token to the neighbors, etc. The main difference lies in the snapshot algorithm initiation: the Snapshot Manager contacts only the starter peer (the one that triggers the whole algorithm process). After receiving the token each starter peer neighbor will initiate the algorithm. The algorithm ends when each peer has received all the tokens from its neighbors and has sent the data collected (the peer state, neighborhood table, etc) to the Snapshot Manager. The Snapshot Manager is able to detect when a snapshot taking is terminated, because, for each EventCloud instance, the number of peers part of the distributed support is known (it is stored as information in the EventCloud registry). Until it has not received the expected number of peer states, this snapshot instance is not valid to be used for a recovery.

Intuition about the corrrectness of the algorithm

To gain an intuitive understanding of some points into the algorithm, let us devise a scenario with an Event Cloud having 3 peers that exchanged requests that may not all be served when the snapshot taking starts. Two of them are faster than the remaining one, that is, serve their requests in a faster manner: they have already exchanged tokens between themselves while the third peer hasn't treated yet its first token. Each of these two faster peers has already saved its state locally (Jena datastore, zone, neighborhood table, etc) during the first token service; now each proceeds serving requests which may generate new requests sent to the slower peer that hasn't already saved its state. In the meantime, received requests sent from the slower peer gets ready to be served by the faster peers, and they will be tagged as in-transit.

More globally, the question we raise is dictated by the fact that in our setting, snapshot taking happens concurrently with the application execution: in a snapshot (set of local peer states or channel states), can it happen that it contains a given information that is not a consequence of the recorded global state ? If yes, this means the system could be recovered from a snapshot that is not consistent, in the sense that it reflects a situation that the system would never be able to reach if restarted from an older snapshot. It is well-known that in a distributed system, message reception suffers from non-determinism of arrival, this explains why different executions and so, different peer states could arise from a same global snapshot restart. Also, these different executions may not exhibiting the same requests, nor the same request contents. Because our snapshot comprises copy of requests tagged in-transit, we must ensure that it is correct to serve them in the recovered execution. Also, because the snapshot comprises peer local state copies, we must ensure that in these states, only information that is the result of what the snapshot encompasses is present: otherwise, this means the state encompasses causal effect of actions but these actions are not supposed to have arisen as summarized by the snapshot content.

In the original Chandy-Lamport algorithm, there is no need to raise this question: a process engaged in the algorithm is applying rules depicted in Figure 1, but in the meantime, it is not processing any of the messages received on its incoming channels, meaning the state that is distributively recorded in the snapshot is not evolving while it's built. On the contrary, in the Active Object model, a peer must proceed serving the requests (in FIFO order by default) to have a chance to process tokens. That means the numerous tokens related actions like local state and channels state savings can happen while peer state has been affected by applicative-level requests service that must eventually not be "visible" (directly or indirectly) in the snapshot. So, for the algorithm to be correct, it must ensure that these effects are left aside and are not wrongly recorded in the snapshot.

First, peer local state saving happens at the very first token service. It only reflects request service effects that must be part of the snapshot. In particular, none of the served requests yielding to the recorded state was tagged as an in-transit request. Indeed by definition, in-transit requests stored in the queue are positioned after the very first token in the request queue, so always served after the peer local state saving, thus having no impact on the saved local state. Also, no request served before the first token service could correspond to a request that should not be part of the global state because was created by a sender after it recorded its own local state (as communication channels in ProActive are FIFO).

The second case discussion is about channel states that are logged, that correspond to in-transit requests within the snapshot. Could it happen that an in-transit request gets recorded in the snapshot alas it should not have been because its originating action is not part itself of the snapshot ? The risk being that in a replay of the system, the execution takes place in a way such that the request that triggered the one tagged in transit and part of the recovered state does not arise. The answer is no: No in-transit request can be a consequence of a request service whose effect is not part of the snapshot.

Thirdly, while the snapshot taking is running on the distributed system, active objects do not stop serving requests, some being detected in-transit requests, some being received before (resp. after) locally entering the snapshot taking execution (so before (resp. after) the first token service). Except for those received before first token service, no impact from their service happens on the snapshot recorded state: local state was copied while serving the first token, which atomically propagated tokens on outgoing channels that, once served will close channels. Consequently, any new request sent on these channels (assumed to be FIFO) cannot affect the receiver recorded local state nor corresponding channel state.

Current limitations

If peers are removed or added to an EventCloud intentionally, according to its associated load balancing strategy, removal or addition of peers is an information that can easily be tracked for recording the effective number of peers. However, notice that supporting removal or addition of peers while a snapshot algorithm is running is left as future work (see section 5). Say another way, the algorithm as it is presented here does assume the number of peers is static, in the sense the topology of the CAN architecture is not changing while the snapshot algorithm is running.

In the current implementation, only one instance of the snapshot algorithm can be running at a time. To initiate the execution of new snapshot algorithm instance the termination of its execution must have been detected. This is a limitation because we may want to periodically put in execution a new algorithm instance, that is, after a certain amount of time a new instance would automatically start, getting a certain overlapping of many global different states. As recovery is triggered from the most recent completed snapshot, it is obvious the less time elapsed since its completion, the best it is as only "few" work is going to be lost and redone. In fact, to support many instances of the snapshot algorithm run in parallel would simply require to extend the current implementation by making all exchanged tokens and associated treatments triggered by the snapshot algorithm tagged by an instance number. For instance, a channel may be closed by a token service of one specific instance, while it may still be open regarding another instance of the snapshot algorithm execution.

EventCloud recovery

Given the snapshot algorithm has allowed to record all the data needed, our next aim is to support the inverse process, that is, reconstruct the system using this information.

Restoration process

When one decides to reconstruct an EventCloud, the Snapshot Manager will trigger the restoration process. According to the snapshot identification, the Snapshot Manager will access the file that contains management information about the EventCloud in question and the state set (from each peer) that contains all the data: neighborhood table, peer request queue, Jena datastore, etc.

The reconstruction algorithm starts similarly to the process of an EventCloud instantiation: when an EventCloud is instantiated, the peers are created with random identifiers, they do the join process according to the CAN protocol to establish the zone they are responsible for and the neighborhood table, etc. However, in the reconstruction process, the peers will be created with well known identifiers, passed as arguments, as this information is already established. Another difference lies in the join phase that is discarded. This phase is useless when reconstructing an EventCloud because the topology information (neighborhood, zone, zone split history) from each peer is already known.

Once the peers created, the data collected must be sent to the peers and some adjustments must be also done. First, the Snapshot Manager sends the corresponding Jena datastore, by using Jsch library, to each peer. This process will create the needed local connection with Jena datastore. Then, the topology data is sent. The topology data is composed by the neighborhood table, peer zone and the split history; however the active object's remote addresses (handled within a stub object) entries in the neighborhood table from each peer is not valid because all the peers were recreated. So, the stub entries need to be updated. To fulfill this task, each peer sends a 2-tuple (id,stub) to its neighbors. Receiving this 2-tuple, the peer will replace the stub in the neighborhood table that corresponds to the id, concluding the update. The list of 2-tuples (id, stub) was created in the peer creation phase. As described before in this section, the join phase in the reconstruction process is useless because the zone and split history are passed to the peers (they were collected). When the peer has received all these topology information it needs to be activated. Consequently, the Snapshot Manager will send a request to turn the peer activated which has as an important side-effect to populate the front of its request queue2 with the in-transit recorded requests. There is no specific per-channel information, as in-transit requests were recorded in the order they were identified, whatever incoming channel they originated from. Hence, the EventCloud is reconstructed, active and ready to receive even additional new requests and serve all of them.

Characteristics of the supported failure model

Risk of information loss

Let's suppose that the snapshot algorithm instance finishes and suddenly one, some or even all peers in the system crash. From the moment of the crash and the system recovery from the last saved global snapshot, the risk is to miss some of the published events, or some subscriptions. While missing events might be catastrophic if they correspond to critical alerts (e.g. from a nuclear plant), in some other situations such loss may be affordable (e.g. if events are used to signal the arrival of new information to subscribed users of a social network).

Recovering published events is impossible if they were injected in the EventCloud at the following moment: before a crash and no peer was able to serve the corresponding request(s) before it terminated its snapshot taking process. Say differently, there is no effect of the published event on the snapshot constituted by the peer and channel saved states. In practice, it is not realistic to log all events injected into an EventCloud, as it might mean logging the entire actions that happen outside the EventCloud, in the external world possibly at web scale.

Subscriptions might be less numerous than publications. Moreover, when a user submits a subscription, the aim is to be kept informed of matching publications that can happen in the future. A subscription stands as a permanent request until it gets removed by the subscriber. It is thus important to devise a practically feasible3 solution to prevent any loss of them. The proposition is as follows.

It consists in a subscription-specific automatic retry mechanism, based upon an extension of the existing EventCloud proxies [START_REF] Stühmer | PLAY Deliverable D1.4 Play Conceptual Architecture[END_REF]]. In more details, it could leverage the fact that the EventCloud relies upon the assumption that all peers participating in the network run a synchronized clock (this is a reasonable assumption for an EventCloud deployed on an administered infrastructure such as a cluster within a data center). As such, it is possible to tag the last snapshot with the most recent clock value corresponding to the moment all peer states have been fully stored. The proxy is in charge of contacting a peer (known as a tracker in P2P terminology) of the EventCloud, to deliver to it the subscription. Each subscription (and event) entering the EventCloud is gaining the clock value at the moment it enters the EventCloud (because the publish-subscribe matching algorithm requires that information) through the contacted peer. Given that, if an injected subscription gets a clock that is greater than the last checkpoint saved clock value, there is a risk in case of failure, that it gets definitively lost. At the proxy side, knowing the clock value associated to the subscription is easy: the contacted peer sends back an acknowledgment of receipt to the proxy (in the form of either a reply updating the future associated to the initiated method call at proxy side, or as a new request from the peer towards the proxy, as a proxy is also an active object). Obviously if the contacter peer fails before the acknowledgement gets back to the proxy, the proxy could after a timeout automatically retry the delivery, once it detects the EventCloud recovery is over. In all cases, even if not facing a crash of the EventCloud, the proxy could keep a copy of the subscription until being sure there exists a more recent snapshot that involves it. Contacting the snapshot manager allows the proxy to know about the latest saved snapshot clock. Before being sure of that, proxy could regularily reinject the subscription in the Event-Cloud, not mandatorily contacting the same peer as peer clocks are synchronized. Given each subscription is uniquely identified, any peer receiving it (because it holds a zone that should index events possibly matching the subscription) could thus avoid duplicating it in the corresponding Jena datastore thanks to this unique identifier.

Discussion about partial or whole EventCloud recovery

In search for a better availability of the EventCloud offered as a service to its end-users, one would like to get a fault-tolerant version where only failed peers and not the whole EventCloud is restarted in case of peer failure. This might be feasible by using a ProActive version implementing the general purpose checkpoint and recovery protocol devised in [START_REF] Baude | Promised messages: Recovering from inconsistent global states[END_REF]]. Indeed, [START_REF] Baude | Promised messages: Recovering from inconsistent global states[END_REF] proposes a protocol by which a new instance of a snapshot algorithm is triggered periodically. This protocol ensures that no message internally exchanged between active objects is lost even in case of some failure takes place. The main challenge solved by [START_REF] Baude | Promised messages: Recovering from inconsistent global states[END_REF]] is how to correctly recover -only-the failed active objects' state of the system given resulting global checkpoint might indeed correspond to an inconsistent global state. To cope with this challenge and restore the system consistently each request exchanged in the execution needs to be tagged by the number of corresponding ongoing checkpoint it should belong to. So the need to rely upon a specific "fault-tolerant" version of the ProActive library which today is not usable with multi-active objects. On the contrary, the Chandy-Lamport algorithm adaptation we propose here doesn't assume the reliance upon a modified Active Object programming library: the support of the snapshot messages is simply programmed by extending the by-default request serving policy of active objects. The mentioned request tag is useful in the checkpointing protocol to turn the necessary requests (those identified as violating the global consistency of the global checkpoint) into promised requests: a recovered peer blocks if trying to serve a promised request, until this request gets filled by the data extracted from its replay. These automatic blocking operations and more tricky actions (see details in the paper) eventually ensure the recovered global state of the system becomes globally consistent.

Notice that this fault-tolerant solution suffers from the same limitation pertaining to possible loss of external information sent to the fault-tolerant application (i.e. the EventCloud), as we discussed in 4.1. In fact, if an active object fails before serving a request which could not have the chance to be part of any snapshot, there is no practically feasible solution to recover it even restarting the execution of the application from the very first state, i.e. from the initial state.

Differently from the aforementioned solution, the solution proposed here constructs a succession of global states which are consistent, and from which a direct recovery of the whole system gets feasible.

Conclusion and perspectives

In this paper, we have presented an adaptation of Chandy-Lamport Snapshot algorithm that works as a best-effort fault-tolerant solution. To validate the work, the reconstruction of an Event Cloud was made by using the data collected from the snapshot recording and verifying if the reconstructed version had the same features of the initial one (same neighborhood set, Jena data, requests queue, etc).

However some improvements can be done. From a pure performance viewpoint, the snapshot algorithm uses a Java-based library to transfer all the data collected to the safe storage place which could be lowered by using a more native approach.

At this point, our implementation doesn't allow the initiation of multiple instances of snapshot being taken from the same Event Cloud at the same time, that is, to start a new algorithm instance the first one needs to be completely finished. More fundamentally, current implementation assumes that the EventCloud architecture is static that is, peers are not assumed to leave or join the P2P network CAN dynamically. Supporting dynamicity requires not only to modify the implementation, but first to devise a slight variant of the protocol itself. Indeed, a channel in the snapshot taking process is closed once a token from corresponding sender gets served. Allowing the sender to intentionnally leave the network while our distributed algorithm runs may imply no token gets sent from its side. An extension of our proposition could be to enforce a gently leave, i.e. informing the neighbours about the intention to leave before effectively leaving the peer-to-peer network. Symmetrically, allowing a peer to join the CAN network means neighbouring sets of neighbour peers grows while a peer may be already participating in a snapshot taking execution. How to consistently incorporate this new peer state in the global snapshot is also to be first devised at the protocol level.

  Figure 1. Key rules of the Chandy-Lamport snapshot algorithm [Chandy and Lamport 1985]

Figure 2 .

 2 Figure 2. Snapshot algorithm execution process. Depicted from only the starter peer viewpoint.

Jsch [jsc

2014] is a Java implementation of SSH2. It allows to connect to a server and uses port forwarding , X11 forwarding, file transfer, etc. As Jsch doesn't allow folder transmission, to be able to transfer the Jena datastore it's necessary to zip its folders.

As peer activation is not an atomic process, it could happen that a peer is activated, serves an in-transit request that generates a fresh request that stands in the neighbour queue at the first place, before the logged in-transit ones. It is thus important to force the logged in-transit ones to be put at first, then only activate the peer allowing it to start serving requests: first the logged ones, then the fresh ones. Letting fresh ones bypass recovered in-transit ones would break the FIFO nature of ProActive channels.

i.e. that avoids systematically logging all information (including publications) that are injected from the external world into the EventCloud

Acknowledgements This work received the financial support of the PROGRAMA CI ÊNCIA SEM FRONTEIRAS, and the European STREP FP7 project PLAY www.playproject.eu.


Pham Thi Hong

Hanh Lemna

Intra-regional trade and income inequality: Where do we stand?

Keywords: Income inequality, Intra-regional trade, Gravity, Asia-Pacific JEL: F14, O11, O15, O24

This paper assesses the link between intra-regional trade and within income inequality. To do so, we use a data sample of nineteen countries in the Asia-Pacific region -one of the most dynamic economic regions. Differing from the existing empirical literature, we employ the gravity model to explain income inequality in function of bilateral trade variables. We find that intra-regional exports can narrow withincountry income inequalities, while the opposite tends to be true for intra-regional imports. Moreover, the creation effect of exports on income inequality seems to be dominated by the diversion effect of imports. Our finding also supports the hump-shaped relationship between per capita GDP and within-country income inequality described by the Kuznets curve.

Introduction

Whether economic integration results in narrowing or widening the within-country income inequalities is still a controversial matter in the international economics' literature. The first set of literature directly tests the existence of a relationship between foreign direct investment (FDI) and inequality. According to [START_REF] Stiglitz | Globalization and its discontents[END_REF], while FDI may bring benefits to the host economy, there is no clear evidence that FDI is associated with an increasing or decreasing inequality within countries. Recently, to analyse the relationship between inward FDI and wage inequality, Figini and Gorg (2011) use a panel of more than 100 countries, classified into two sub-categories, OECD and non-OECD countries, over the period . They find that FDI's effect differs due to the development level of each country. For developing countries, wage inequality increases with inward FDI stock but this effect diminishes with further increases in FDI, while wage inequality decreases with inward FDI stock for developed countries.

The second set of literature tends to access the impact of trade openness on income disparities. [START_REF] Bourguignon | Income distribution, development and foreign trade: A crosssectional analysis[END_REF] suggest that trade openness' impacts on inequality depend on the relative factor endowments of a country. In the same line, [START_REF] Spilimbergo | Income distribution, factor endowments, and trade openness[END_REF] and [START_REF] Fischer | The evolution of inequality after trade liberalization[END_REF] find that openness increases inequality, and that trade effects undo the direct effects of endowments. Similarly, [START_REF] Barro | Inequality and growth in a panel of countries[END_REF] and [START_REF] Milanovic | Can we discern the effect of globalization on income distribution? Evidence form household survey[END_REF] argue that trade openness is associated with greater income equality in rich countries, while the opposite tends to be true for poor countries. According to [START_REF] Meschi | Trade and income inequality in developing countries[END_REF], trade, in particular trade with rich countries, tends to aggravate wage inequalities across manufacturing sectors in developing countries. Considering the specific trade patterns of each country, [START_REF] Bensidoun | International trade and income distribution: reconsidering the evidence[END_REF] assess the effect of international trade upon income distribution, which is measured by the changes in Gini index. They find that a change in the factor content of trade significantly influences income distribution and that the sign and magnitude of this impact is conditional on the national income level. In detail, an increase in the labour content of trade raises income inequality in poor countries, but reduces income inequality in rich countries, while the opposite tends to be true for the capital content of trade.

However, the existing works seem to focus only on the possible impacts of aggregate FDI and trade, while the link running from bilateral economic integration to income distribution has been a relatively neglected area. Recently, Martinez-Zarzoso and Vollmer (2011) tend to resolve this issue but especially regard the impact of between-country income distribution similarities on bilateral trade. To do so, they use the national income distribution to calculate income similarity indices. These indices allow one to measure how much each country pair overlaps in terms of income distribution and population. Estimating an augmented gravity equation, Martinez-Zarzoso and Vollmer (2011) find that an increase of 10% in income-distribution similarities increases exports by almost 4%. Yet, in this study, the authors have neglected the inverse question of whether bilateral economic integration (in both terms trade and investment) can narrow or widen within-country income inequalities. Our present paper, therefore, tends to fill this knowledge gap.

Yet, studying the impact of bilateral FDI flows on income inequality is seriously infeasible due to the data availability. Thus, this paper only focuses on the bilateral trade's impacts on income inequality. To do so, we develop an empirical analysis in the case of Asia-Pacific region, which has experienced a "noodle bowl" of bilateral and minilateral preferential trade agreements.

A specificity of the present paper is that we investigate the impact of intra-regional bilateral trade on within-country income inequality. We also attempt to tackle another question of whether an increase in intra-regional trade could reduce the gap in within income inequalities between Asia-Pacific countries. Moreover, to achieve the research goal, we employ an augmented gravity equation, which has been widely used in the international economics literature. We use the Gini index as the main indicator to measure within-country income inequalities for a panel of nineteen selected Asia-Pacific countries over the period 1998-20011. It is also worth noting that Gini is the most widely used indicator for comparisons of within-income distribution across countries and over time. For this reason, we choose the Gini as a benchmark indicator despite its well-known short-comings. This paper is organized as follows. The next section reviews the theoretical background which motivates our empirical analysis. Section 3 outlines some stylized facts about recent trends of mushrooming preferential trade agreements as well as within-country income inequality in the Asia-Pacific region. Section 4 presents the empirical approach and describes the data. We report and analyse econometric results in Section 5. Concluding remarks are in Section 6.

Trade and income inequality: Literature review

The impact of international trade on income distribution has been widely studied in the international economics literature. However, the conclusions about this topic have been ambiguous. Firstly, many empirical studies are based on the pioneer theoretical works developed by Heckscher-Ohlin and Stolper-Samuelson (H-O-S), in which a country exports (imports) the goods if the production process of this goods employs the factor relatively more (less) abundant.

Consequently, an increase of the abundant factor results in an inequality shrink in developing countries and an inequality fall in developed countries. These hypotheses are empirically verified in [START_REF] Li | Explaining international and intertemporal variations in income inequality[END_REF]. Considering exports as an openness measure, the authors find that the relationship between exports and income distribution is negative. However, in the Chinese case study developed by [START_REF] Wei | Globalization and inequality: evidence from within China[END_REF], exports decrease rural-urban income inequality.

Accordingly, the positive impact of exports on income distribution could be explained by the naissance of new industrial agglomerates within Chinese rural areas. However, the H-O-S theorem is only partially supported in Reuveny and Li (2003), who suggest that trade decreases income inequality in both developing and developed countries. Employing two alternative openness indicators, [START_REF] Lundberg | The simultaneous evolution of growth and inequality[END_REF] find quite different results about the link between openness and income distribution. The de jure openness indicator (measured by the Sachs-Warner index1 ) positively affects income inequality, whereas the de facto openness' impact (measured by the sum of imports and exports as a percentage of GDP) is not significant. These findings are also supported by [START_REF] Dollar | Trade, growth and poverty[END_REF].

Secondly, differing from the empirical works listed above, [START_REF] Davis | Trade liberalization and income distribution[END_REF] argues that the theoretical link between trade and income distribution in the H-O-S model may be reversed if one takes into consideration the country's production factor abundance (capital and labour). The fact is that a rich country can be deemed as capital abundant relatively to its production and that its wages will be reduced by trade. Extending the study of [START_REF] Davis | Trade liberalization and income distribution[END_REF], [START_REF] Cooper | Growth and inequality: the role of foreign trade and investment[END_REF][START_REF] Milanovic | Can we discern the effect of globalization on income distribution? Evidence form household survey[END_REF] indicate the channels through which trade increases income inequality in the poorest countries and decreases it in middle-income and high-income countries. Unlikely, basing on theoretical predictions that the impact of trade openness on inequality depends on the relative factor endowment of a country, [START_REF] Spilimbergo | Income distribution, factor endowments, and trade openness[END_REF] find a negative link between trade and income distribution in countries with a relatively high endowment of skilled workers, whereas a positive link in countries that are relatively capital-abundant. In the same light, [START_REF] Meschi | Trade and income inequality in developing countries[END_REF] try to explain why trade can significantly influence income inequality in developing countries. To do so, they employ the FDI model of [START_REF] Feenstra | Foreign Direct Investment and relative wages: evidence from Mexico's maquiladoras[END_REF], in which skill-intensive technologies shift from developed to developing countries through trade channels. An increase in skilled labour demand becomes a main channel through which trade can affect income inequality. Feenstra and Hanson find that exports from developing to developed countries appear to be significantly and positively correlated with income inequality. This finding is also previously concluded in transition economies. For instance, [START_REF] Aghion | On the dynamics of inequality in the transition[END_REF] find that international trade growth leads to a fall in unskilled labour demand and a consequent increase in income inequality.

Moreover, the impacts of trade on within-country income inequality may differ and depend on the country's income level. [START_REF] Barro | Inequality and growth in a panel of countries[END_REF] and [START_REF] Milanovic | Can we discern the effect of globalization on income distribution? Evidence form household survey[END_REF] find evidence that trade openness is associated with greater income inequality in poor countries, while the opposite tends to be true for rich countries. Lately, [START_REF] Meschi | Trade and income inequality in developing countries[END_REF] suggest that that trade with rich countries tends to aggravate wage inequalities across manufacturing sectors in developing countries. In another empirical work, [START_REF] Bensidoun | International trade and income distribution: reconsidering the evidence[END_REF] tend to reassess the link between international trade and income inequality in a framework of factor endowments' theorem.

Accordingly, one way to assess the influence of international trade upon income distribution is to take into account the country's specific trade patterns by measuring the changes in trade's factor content. The author show that a change in the factor content of trade has a significant impact on income distribution and that the sign and magnitude of this impact is conditional on the national income level. Precisely, an increase in the labour content of trade raises income inequality in poor countries, but reduces income inequality in rich countries (the reverse is true for the capital content of trade).

We now turn our attention to the studies, which focus on the link between bilateral trade and income distribution. To the best of our knowledge, a few recent studies have considered the within-country income distribution as an important determinant of bilateral trade flows. Among others, Martínez-Zarzoso and Vollmer (2011) recently tend to test the two theoretical predictions of [START_REF] Markusen | Putting Per-Capita Income back into Trade Theory[END_REF]: i) a positive dependence of trade on per capita income; and ii) higher inequality increase trade of more sophisticated goods. They find that per capita income is positively related to bilateral trade and that on average, an increase of 10% in income-distribution similarities increases exports by almost 4%. Moreover, this effect is stronger for more sophisticated goods in comparison with more homogenous ones. By contrast, the recent literature seems to ignore the reverse question of whether bilateral trade is associated with a deepening or lessening of income inequality within countries as well as between countries in the same geographic zone. So that, our present paper endeavours to fill this knowledge gap by providing in the next sections a case study of the Asia Pacific region.

On the dynamics of trade and inequality in Asia-Pacific region

The Asia-Pacific region consists of diverse economies ranging from very small to the world's biggest countries, from continental economies to island states. This region has also experienced a very diverse level of economic development, with a very wide range in GDP per capita as well as in income distribution. Despite these differences, the Asia-Pacific countries share in common the desire for closer economic integration and improvement in intra-regional economic development.

With respect to the research objectives, this section, first, looks at the actual development of trade in the Asia-Pacific region. This is followed by the divergence of within-country income inequalities in the region.

Trade integration

In the last decade, dynamic processes have emerged and led to the creation of an integrated space in the Asia-Pacific region. This region offers a relatively special image of mushrooming bilateral Free Trade Agreements (FTA) in the world. Particularly, the Asia-Pacific Economic Cooperation (APEC) forum's "open regionalism" and the extension of trade concessions to non-members have been praised an APEC regionalism model since 1989, which corresponds to the global free trade.

Figure 1 shows that the last decade has experienced a rising trend in the enforcement of bilateral FTA between the country members. Source: Adopted from UNESCAPE According to [START_REF] Arbabzadeh | Trade integration in Asia: Is the region pursuing a convincing strategy for the 21 st century?[END_REF], the reasons for this remarkable integration process are manifold. First, Asia-Pacific has marked a significant reduction in armed conflict. A number of regional conflicts (notably, the Korean and Vietnam Wars and the conflicts in Southeast Asia in the 1970s and 1980s) have been solved or are dealt with in a non-military manner. Second, the Asia-Pacific countries have learned that economic instability is a greater concern to them than classical security risks. Furthermore, the closer economic growth of Asian countries together with the deepening of transnational production networks, the growing share of intra-regional trade and substantial investment flows provide the necessary conditions in which a process of regional political cooperation is gradually being built. Following a rising trend in the signed bilateral FTA, the Asia-Pacific region has also evidenced a sharp increase in regional trade flows. Following an increase in trade dependence, the export orientation of Asia-Pacific region had changed during the period 1995 -2007. Among others, the share of exports from emerging markets such as China, India and ASEAN 2 countries was doubled, from 11.5% to 23.6%. This period also experienced a structural change in the export destinations. The share of three developed market destinations, including the EU, Japan and the US dropped from 46% to 38%. Similarly, there was a significant increase in export dependence in favour of three emerging markets listed above. These trends allow one to conclude that Asia-Pacific was on the path to decoupling itself from developed markets.

The Asia-Pacific regionalism has been also characterized by a large number of sub-regional trade agreements as follows:

ANZCERTA -Australia and New Zealand ANZSCEP -New Zealand and Singapore BIMSTEC -Bangladesh, India, Sri Lanka, Thailand (no data for Bhutan, Myanmar, Nepal) SAFTA -Bangladesh, India, Maldives, Pakistan, Sri Lanka (no data for Bhutan and Nepal)

Moreover, the Asia-Pacific region has also experienced the concentrated trade flux in some sub-regions, such as ANCERTA, ANZSCEP and ASEAN. For instance, imports and exports between ASEAN countries increased from 1.5% to 18.7% and from 1.8% to 20.5% respectively during 1998-2007. On the other hand, the largest increase in intra-subregional imports is between ASEAN and APTA zones with a doubled increase in export flows and a tripled increase in import flow. This trend can be explained by the fact that in North-East Asia, South-East Asia and Asian emerging countries, there is an increase in the share of intra-industry trade, signalling stronger regional integration and cohesiveness of production systems.

Trade integration versus within-country income inequality

Most countries in the Asia-Pacific region have relied on a strategy of trade integration and exportled growth for more than three decades. This strategy has been led by a number of regional or subregional FTAs that have the proven benefits in terms of faster growth and development. However, the effects of this openness strategy may be negative for the welfare of the participating countries as well as the stability of the multilateral trade regime. Regarding to the research objective, this sub-section provides some evidences on the possible interaction between trade integration and within income inequality in this region. However, because of the data availability, we only focus on the stylized facts of nineteen Asia-Pacific countries (see further Appendix A for country list).

<Table 1: Matrix of bilateral trade agreements> Table 1 presents a matrix of bilateral trade agreements between the countries under consideration. Accordingly, the last decade has experienced the registration of a large number of BTAs in the Asia-Pacific region. This element has seemed to be a factor explaining the rising level of trade dependence between the studied countries.

<Figure 3: Intra-regional export and import growth>

As displayed in Figure 3, the intra-regional export and import flows had been dramatically rising over the period 1998-2007. For example, exports and imports between Vietnam and other selected Asia-Pacific countries increased by 515% and 472% respectively from 1998 to 2007. However, there is no clear evidence of the changes in trade structure (in terms of intra or extra-regional trade). As shown in Figure 4, each country has experienced a different trend in the share of intra-regional trade. For instance, Vietnam evidenced a growing trend in the share of both intra-regional exports and imports, while India experienced an opposite trend. This phenomenon could be explained by the fact that bilateral trade between Asia-Pacific countries has only increased if these countries share a common trading bloc, such as ANCERTA, ANZSCEP and ASEAN.

<Figure 4: Share of intra-regional trade> Now we look at the possible impact of intra-regional trade on income distribution. As mentioned in the previous section, many empirical works argue that trade openness may have a significant contribution to widening income inequalities in developing countries, while the opposite tends to be true for developed countries.

<Figure 5: Income inequality and intra-regional trade>

As displayed in Figure 5, the relationship between inequality measured by Gini coefficient and intra-regional trade is such heterogeneous and diverse through Asia -Pacific countries. Data from Australia, Japan and New Zealand show no evidence of a link between income inequality and regional trade, while the US data do approximately a U-shaped pattern. No clear-cut relationship between income distribution and intra-regional trade is also observed for the case of three emerging and high-income countries including Singapore, Korea and Malaysia. The connection between inequality and intra-regional trade in other emerging countriesseems to be more complex and heterogeneous. This connection is presented by a U-shaped pattern in some countries but by a U -inverted pattern in other ones.. Lastly, data from developing and lowincome countries show no evidence that rising trend in intra-regional can widen or lessen income inequalities. In general, the question of whether the extension of intra-regional trade in Asia-Pacific region negatively or positively influences the degree of inequality cannot be institutively resolved.

Therefore, the next sections will provide an econometric analysis to investigate such a complex relationship.

Model and data specifications

As mentioned above, the aim of this paper is to investigate the potential impacts of trade integration on within income inequality in a panel sample of nineteen selected Asia -Pacific countries over the period 1998-20011. We apply an augmented gravity model that has been widely used to analyse the determinants of international trade flows. In our augmented gravity equation, we consider the income inequality as endogenous variable explained by traditional gravity variables (notably the country size, distance and language), trade variables and so on. With respect to the basic structure of a conventional gravity equation, the augmented gravity equation is defined as follow:

= + + + ∑ + ∑ + ∑ + (1)
where GINI is the Gini coefficient measuring within-country income inequality at the time t. In this paper, to compare the difference in GINI level between the countries of interest, we do the econometric tests for two separate gravity models:

The first one employs the ratio as a dependent variable (where GINIit is the Gini coefficient of the export/import countries i, and GINIjt is the Gini coefficient of the import/export countries j at the time t). Employing this ratio allows us to answer whether intra-regional trade can deepen or worsen the Gini level's gap between trading country partners. For instance, a positive value of any explicative variable's estimated coefficient implies that an increase in this variable's value is associated with the widening gap in the Gini level between trading countries.

The second one utilizes the GINIit index of export country as a dependent variable.

Utilizing this indicator allows us to evaluate whether intra-regional trade allows the Asia-Pacific countries to reduce the Gini value and so within-country income inequality. For instance, a positive value of any covariate's estimated coefficient means that an increase in this variable's value leads to a higher Gini coefficient or an increase in within-income inequality.

We now turn to the definition of each explicative variable. EXijt is real exports from country i to country j at time t; IMijt is real imports from country j to country i at time t. GRAit includes a set of traditional gravity variables as follows:

GDP per capita (labelled GDPper) of the export countries;

The quadratic term for GDP per capita (labelled GDPper 2 ) is also introduced in all regressions to take into account the possible presence of an invested-U relationship between economic growth and income inequality described by the Kuznets curve.

Population in volume (labelled POP);

The distance between the export and import countries (denoted DIS);

The common language between the export and import countries (denoted LAN);

The common border between the export and import countries (denoted BOR);

CONit is a vector of control variables assumed to be correlated with inequality. According to the literature on wage inequality, we introduce four control variables:

Open to foreign investment is defined and measured as total stock of inward FDI over GDP. Including FDI inflows allows us to revisit the impacts of FDI on income inequality.

This issue has also discussed in many theoretical works. For instance, presenting a model of technology transfers through the FDI channel, [START_REF] Wang | Foreign Investment and Technology Transfer: A Simple Model[END_REF] suggest that workers with more human capital will appropriate more of the beneficial effects of FDI than unskilled workers. Focusing on the firm specific nature of FDI, [START_REF] Zhao | The Impact of Foreign Direct Investment on Wages and Employment[END_REF] examines the impact of FDI on wages and employment more directly. According to Zhao, inward FDI benefits the workers with greater bargaining power. In this paper, we use the stock value of inward FDI, which is defined as "the value of the share of their capital and reserves (including retained profits attributable to the parent enterprise, plus the net indebtedness of affiliates to the parent enterprises" (World Investment Report, 2009).

Together with inward FDI variable, we also control for de facto trade openness that is measured by the ratio of total exports and imports to GDP (denoted OPEN).

The level of education (denoted EDU) is used to control for the supply side of the labour market. This control variable is measured by the total number of students enrolled in secondary education as a percentage of the total population. We would expect that, higher the enrolment ratio is, higher the supply of skilled labour is. An increase in the skilled labour supply, in turn, can reduce income inequality.

According to Acemoglu (2003a), labour market's institutions can affect the overall level of inequality. To control for this impact, we include in the gravity model two variables, notably the minimum wages (labelled MG) and the centralization of wage bargaining (labelled WB).

Inflation rate (labelled INF) is to control for the macroeconomic instability of each country under consideration, which may positively influence inequality, by raising wages especially in the lowest part of distribution.

We now look at the selection of dummy variables DUMit:

FTA1it is a binary dummy which is unity if there is a FTA between trading partners; FTA2it is a binary dummy which is unity if the trading country partners share at least a common multilateral FTA;

PARTinit is a binary dummy which is unity if only one trading country is WTO member;

ALLinit is a binary dummy which is unity if both trading partners are WTO members;

Empirical results

We realize the econometric tests for two baseline gravity models. The first one considers the ratio GINIit as the dependent variable, while the ratio " "

becomes the dependent variable in the second model. We first estimate each model by using the Ordinary Least Squares (OLS) estimator with heteroskedasticity-consistent standard errors. The OLS results are reported in the second and third columns of Table 2.

OLS estimator's results

We start with a discussion on the estimated values of trade variables, which captures the impact of intra-regional trade on within income inequality. The EX variables enter in all regressions with a negative and significant coefficient at the 1% level. It means that as intra-regional exports increases, within income inequality decreases and also the gap in income inequality between countries decreases. Yet, the effect of intra-regional exports on Gini and relative-Gini is pretty weak. By contrast, the IM coefficient is positive but only significant in the first regression, suggesting that intra-regional imports can increase absolute within-country inequalities but has no impact on changing the inequality gap between trading partners. On the other hand, global trade integration, measured by the OPEN variable, results in deepening either absolute within-country income inequalities or the inequality gap between countries.

A further interesting result concerning the role of intra-regional trade stems from the coefficients of three other covariates BE1-2-3. The non-significance of BE3 coefficient implies that intra-regional trade between developing countries does not explain the change in their income inequalities.

Otherwise, a significant and positive value of the variable BE1, only in the " " equation, means that trade flows between developed countries can increase the gap in income inequalities between these countries. We find a similar result for the case of bilateral trade flows between developing and developed countries. In this case, we can consider that developing countries have suffered the negative impacts of trading with developed countries. This finding is further reinforced by the positive value of two other dummies CON3 and CON4, implying that intra-regional trade flows may be associated with a rise in within income inequalities only in developing countries.

Theoretically, developing countries' imports from developed countries bring more sophisticated technology and create a gap between the importing firms, which able to upgrade their assets then increase the skilled labour demand, and the rest of firms. This mechanism has been explained by [START_REF] Feenstra | Foreign Direct Investment and relative wages: evidence from Mexico's maquiladoras[END_REF] in the case of trade between Mexico and the USA. In an opposite situation, the exporting firms in developing countries are not required to improve the technological level of exporting goods, given that most of them are primary commodities. Thus, a stable or even increasing demand for unskilled labour in exporting firms and a rising demand for skilled labour demand in importing firms may adversely affect income inequality. In general, when a developing country opens to trade, they become more exposed to technologies and innovations produced in more advanced countries. Hence, trading with richer countries, which should involve technological upgrading, leads to a general shift of labour demand towards more skilled workers, a consequent increase in wage differentials and a subsequent increase in inequality. In contrast with developing countries, emerging high-income countries (notably Singapore, Korea and Malaysia) seem to be benefit from intra-regional trade. This is evidenced by the statistically significant and negative value of CON2 coefficient. Briefly, while intra-regional export flows can reduce within-income inequality, the opposite tends to be true for intra-regional import flows. Furthermore, the positive and significant value of OPEN variable, which measures the openness level of a country to trade (either intra or extra-regional), enables us to identify the mechanisms of transmission between globalization and income distribution: more opened economics, higher within-income inequality.

We now look at the impact of inward FDI flows. As mentioned above, due to the data limitation, FDI is only considered as a control variable and measured by the share of total inward FDI stock to GDP. It is worth noting that the FDI coefficients are positive and statistically significant in all regressions. It means that inward FDI flows are associated with widening within-income inequalities in the Asia-Pacific region. In fact, the new technology is transferred from developed countries to developing countries through the FDI channel. As the multinational firms have successfully implemented the new technology in the host country, only skilled labour will be required. Consequently, demand for skilled labour steeply increases, thus leading to an increase in wage of skilled labour and income inequalities between skilled and unskilled labour. This finding has been also supported in other earlier empirical studies. For instance, using a sample of 33 developing countries, [START_REF] Tsai | Foreign Direct Investment and Income Inequality: Further Evidence[END_REF] studies the link between FDI and inequality and finds that FDI increased inequality in some Asian countries. [START_REF] Gopinath | Foreign Direct Investment and Wages: a Cross-Country Analysis[END_REF] argue that FDI flows widen the skilled -unskilled wage gap for a sample of 11 developing countries. In a panel study of 80 countries, Basu and Guariglia (2006) confirm the theoretical proposition about the role of inward FDI in fostering income inequality. Similarly, [START_REF] Figini | Does Foreign Direct Investment Affect Wage Inequality? An Empirical Investigation[END_REF], who analyse the relationship between foreign direct investment and wage inequality in a panel of more than 100 countries, conclude FDI inflows as a channel of new technology transfer, which in turn influences wage distribution. Although our empirical results on the role of FDI is satisfactory and consistent with that of previous studies, our present paper has not yet resolved another important question of what kind of bilateral FDI flows3 may widen within income inequality. We leave this issue for further researches.

As mentioned above, we introduce in all gravity models two variables -the log GDP per capita and its quadratic term -in order to control for the possible existence of a Kuznets curve, extensively studied in the literature (e.g., [START_REF] Barro | Inequality and growth in a panel of countries[END_REF]. The empirical results allow us to confirm the importance of controlling for a Kuznets-type effect. The significant impacts of per capita GDP variable and its squared value, which are positive and negative respectively, are consistent with the hump-shaped relationship between per capita GDP and income inequality described by the Kuznets curve. Regarding other country size variables, we find that the estimated coefficients of the population variables (POP) are positive and statistically significant at 5%, meaning that the population growth is probably a factor increasing income inequality. This paper also evidences the impacts of other macroeconomic variables on income inequality. First, as expected, the inflation INF coefficients are significantly positive at least the 5% level. It means that an instable macroeconomic situation is associated with an increase in income inequality. Second, education plays an important role in narrowing income inequality. A high educational level EDU may intensify and even accelerate the diffusion of knowledge entering the developing countries through trade flows between them and developed countries.

Another important finding is that becoming a WTO member differently affects withinincome inequality. If both trading countries are WTO members within income inequality tends to increase. By contrast, if only one partner is WTO member, we cannot conclude the WTO effect on Gini value. This finding, by and large, supports evidence of the diversion effect of WTO membership. The fact is that the WTO accession allows a country to benefit from the tariffs reduction and trade barrier elimination. However, WTO accession's impact on within-income inequality are quite diverse across countries, ranging from negative to positive and from direct to indirect (e.g. Rose, 2004a/b;2005). On the other hand, belonging to WTO also causes stronger foreign competition in the domestic market of a country. Foreign competition, in turn, can result in two possible strategies for the domestic producers. The first one is to lower prices and improve the quality of their domestic products. The second is to re-allocate their production activities abroad through the vertical FDI channel. The latter seems to be the better choice since it allows the domestic producers to: (i) avoid foreign competition, (ii) benefit from the foreign investment incentive in the FDI host countries, and (iii) re-export their products to the domestic market and benefit from the tariff reduction. This decisive strategy can decrease labour demand and wage level in the FDI home countries. In the FDI host country, foreign firms' entry can widen the wage gap between domestic and foreign firms, which in turn encourage the within-income inequality.

Unlike the WTO impacts, the FTA1 (in the " " equation) and FTA2 coefficients enter in all regressions with a negative but statistically insignificant value. It means that sharing a BTA or a common trading block does not contribute to the change in income distribution. This finding allows us to ask the efficiency of Asia-Pacific integration policies in achieving free trade. As discussed above, the Asia-Pacific region has been considered as a good example not only of "open regionalism" but also of the trade concessions' extension to non-members. Although de jure intraregional integration is growing, deeper de facto integration is probably lagging. The Asia-Pacific region has seemed to experience a slow progress and a lack of significant trade concessions that have frustrated free-trade hopefuls in academia and the business world alike (UNESCAP, 2008).

This phenomenon results from the diverse interests and differing approaches in the region toward free trade. Moreover, rather than focusing on and pursuing an intra-regional Asia-Pacific model, the region is characterized by several competing approaches to free trade, reflecting diverse domestic interests and complex strategic and tactical alliances. However, it should be noted that diversified characteristics of intra-regional trade regimes may be an outcome of an important gap in economic development levels between the Asia-Pacific countries. In such a context, pursuing a common and unique intra-regional Asia-Pacific model is not an easy task. Moreover, only FTA1 coefficient in the GINIit equation is significant and negative, additionally suggesting that the bilateral trade agreements can decrease the Gini index but cannot change the income inequality gap between trading country partners.

Robustness checks

In the second step, we check for the robustness of OLS estimator's results by performing two alternative econometric tests. The first one is the HTM estimator originally proposed by [START_REF] Hausman | Panel Data and Unobserved individual effects[END_REF]. According to [START_REF] Egger | A note on the proper specification of the gravity equation[END_REF]and 2002b), the HTM technique is considered as the most appropriate estimation of cross-country gravity model. The HTM estimator's results (2 nd and 4 th columns, Table 2) show that applying the HTM technique to estimate all gravity equations does not alter the sign or the statistical significance of explanatory variables. Only the magnitudes of estimated coefficients are little affected. In other words, the HTM estimator's results as effectively supportive of the robustness of the OLS estimator's results.

However, the HTM method assumes that some of the explanatory variables are correlated with the individual-level random effects, but that none of the explanatory variables are correlated with the idiosyncratic error. According to [START_REF] Nickell | Biases in Dynamic Models with Fixed Effects[END_REF], this correlation can make the panel estimation equations suffer from the estimation bias. Among other methods, which can correct the country specific or time-specific effects and allows getting rid of any endogeneity in explanatory variables, the Instrumental Variables estimator is a preferred estimator. However, determining the IV in each estimated gravity equation is not an easy task. In this paper, we will instrument the export/import and inward FDI variables, which are considered as endogenous ones, with a set of following external variables:

-Trade variables are instrumented with the trade concentration/diversification index, the most-favoured nation rate and the exchange rate;

-Inward FDI variable is instrumented with the KAOPEN index4 and the exchange rate.

Above all, we test for the validity of each instrumental variable. In the lower part of Table 2, we report the weak instrument test suggested by [START_REF] Stock | Testing for weak instruments in linear IV regression[END_REF] and the Hansen/Sargan test of over-identifying restrictions. On one hand, in the weak instrument test the Cragg-Donald Fstatistics are superior to the critical value of 10% maximal IV size proposed by [START_REF] Stock | Testing for weak instruments in linear IV regression[END_REF], meaning that the null hypothesis of weak instruments is rejected. On the other hand, the Sargan/Hansen test of over-identifying restrictions, which is reported in the last line, checks the validity of the instruments. According to the empirical results, we cannot reject the null hypothesis of Sargan/Hansen test meaning that the instruments are valid instruments, notably uncorrelated with the error term, and that the excluded instruments are correctly excluded from the estimated equation.

The IV results reported in the last columns of Table 2. The results are also similar to those of the OLS estimator in terms of sign and significance, but the magnitudes are different as would be expected. The explanatory variables enter with much smaller coefficient than using the OLS technique. It remains, however, highly significant. Otherwise, the IV estimation provides two complementary results to those of OLS and HTM estimators. First, when we treat the openness variables (including trade and inward FDI) as endogenous, the imports IM variables become positive and significant at least the 5% level. This result supports the hypothesis that imports are the channel of transferring the new technologies, which in turn deteriorate within-income distribution. Second, the treatment of the openness terms as endogenous also makes the BE3 coefficients negative and significant, while the BE1 and BE2 coefficients remain their sign and statistical significance. Thus, trade between developing countries seems more susceptible to endogeneity bias than trade between other countries. Interestingly, this result means that intraregional trade between developing countries can improve within-income distribution in these countries.

Conclusion

This paper assesses the impact of intra-regional trade on within-country income inequality in the Asia-Pacific region. We use a data sample covering the bilateral trade flows between 19 selected Asian-Pacific countries over the period 1998-20011. Differing from the existing empirical studies, this paper is the first using the gravity model to investigate the link running from bilateral intraregional trade to within-country income inequality. Using three alternative econometric techniques (OLS, HTM and IV) our empirical results, by and large, are satisfactory and robust.

The most important finding is that increasing intra-regional exports can narrow withincountry income inequality. This finding supports the creation effect of intra-regional exports.

However the opposite tends to be true for the impact of imports. This result matches the theoretical hypothesis on the imports' role in conducting for new technology transfer, which in turn promotes domestic firms to employ more skilled workers and so widens wage inequality. The paper also reveals that intra-regional trade between developed and developing countries can worsen the income inequality gap between them. In other words, developing countries can suffer the negative impacts of trading with developed countries. By contrast, intra-regional trade between countries at the same level of economic development tends to exert the opposite effect. In general, these results allow us to conclude that encouraging intra-regional trade integration between countries at the same level of economic development may avoid the undesired diversion effects of trade on within-country income inequality. While intra-regional exports and imports differently influence income distribution, a positive and significant value of the trade openness indicator (measured by the ratio of total exports and imports to GDP) implies that more a country opens to trade, higher its income inequality is. In this sense, we can conclude that the creation effect of exports on inequality seems to be dominated by the diversion effect of imports. In sum, if trade is considered as the main channel of new technology transfer, technological differentials and the skill biased nature of new technologies, in turn, may be important factors in shaping the distributive effects of trade.

Our empirical study also provides further interesting results on the role of other macroeconomic variables. First, a rising trend in inward FDI, one of the most important channels to transfer the new technologies between countries, may widen within-country income inequality.

Second, a hump-shaped relationship, described by the Kuznets curve, between GDP per capita and within-country income inequality is also confirmed in this study. Third, our empirical result supports the determinant role of education in decreasing within income inequality.

The last important result concerns the link running from intra-regional trade agreements to within-income inequality. As mentioned above, the Asia-Pacific region has experienced the most dynamic trade integration bloc explained by the registration of a large number of BTAs. Our empirical analysis, yet, reveals that the registration of BTAs is growing, but deeper and more efficient implement of BTAs is lagging. Econometrically, we find no evidence of the efficiency of intra-regional BTAs in lessening within-country income inequality or in correcting the gap in income distribution between countries. This unexpected result can be explained by the recent regional developments and trends in trade policies. Instead of practising a unique intra-regional model, the Asia-Pacific trade integration policies are characterized by several competing approaches to free trade, reflecting diverse domestic interests and complex strategic and tactical alliances. As a result, these strategies lead to a numerous different sub-regional integration policies, which have seemed to boost only the sub-regional cooperation in trade and investment and to turn it into the principal driver of promoting economic growth without narrowing withincountry income inequality in particular, and achieving the Millennium Development Goals in general. ; Values in parentheses are robust standard errors. ***, **, *: Significant at 1 percent, 5 percent, 10 percent level respectively. () a , Critical value of 10% maximal IV size proposed by [START_REF] Stock | Testing for weak instruments in linear IV regression[END_REF]. Values in brackets are P-values.

Figure 1 :

 1 Figure 1: Noodle bowl of bilateral trade agreements in Asia-Pacific, 2009

Figure 2

 2 Figure2shows how quickly exports of the largest and most dynamic traders of the Asia-Pacific region reacted to the contraction of import demand. Figure2also illustrates that although openness has its proven benefits in terms of faster growth and development, increased trade dependence (notably increase in exports) can favourite the vulnerability to external shocks. For instance, the region had enjoyed the prolonged periods of high export, interrupted briefly by the 1997 Asian financial crisis, and then the 2000 dot-com crisis. Recently, the exports growth of many countries sharply slid into a negative value during the period 2008-2009 as economic conditions in the largest importing markets became worse (notably the US demand for imports).

Figure 2 :

 2 Figure 2: Exports growth of selected Asia-Pacific countries

  , China, India, Republic of Korea and Sri Lanka (no data for Lao PDR) ASEAN-Cambodia, Indonesia, Malaysia, Philippines, Singapore, Thailand (no data for Brunei Darussalam, Lao PDR, Myanmar and Viet Nam)

  CON1 through CON4 are binary dummies capturing the country fixed effects classified into 4 sub-categories: developed, emerging and high income; emerging; and developing countries. BE1, BE2 and BE3 are binary dummies which are unity if trading flows are between two developed countries, between developed and developing countries, and between two developing countries respectively. To this end, our empirical study is based on an unbalanced annual panel data covering various individual indicators for nineteen selected countries in the Asia-Pacific region over the period 1998-20011. All these indicators are transformed in the natural logarithm. The sources of data sample as well as the list of countries under consideration are presented in Appendix A.

Figure 3 :Figure 4 :

 34 Figure 3: Intra-regional export and import growth 1998 -2007

Table 2 : Empirical results

 2

	Dependant variables	OLS estimator	Haussman-Taylor estimator	IV estimator Trade variables instrumented Inward FDI instrumented
		Model I	Model II	Model I	Model II	Model I	Model II	Model I	Model II
	EX	-0.008*** (0.002)	-0.018*** (0.004)	0.000 (0.001)	-0.009** (0.004)	-0,104*** (0.015)	-0,196*** (0.026)	-0,008*** (0.002)	-0,019*** (0.005)
	IM	0.006*** (0.001)	0.006 (0.004)	-0.000 (0.001)	-0.000 (0.003)	0,077*** (0.011)	0,142*** (0.021)	0,006*** (0.001)	0,007* (0.004)
	TO	0.184*** (0.010)	0.206*** (0.022)	0.036** (0.017)	0.065*** (0.014)	0,319*** (0.024)	0,441*** (0.073)	0,187*** (0.000)	0,212*** (0.023)
	GDPper	0.841*** (0.115)	0.846*** (0.260)	2248*** (0.193)	2.464*** (0.549)	0,673*** (0.238)	0,680* (0.523)	1,387*** (0.137)	1.223*** (0.277)
	GDPper 2	-0.044*** (0.006)	-0.043** (0.015)	-0.118** (0.011)	-0.128*** (0.030)	-0.37*** (0.013)	-0,059*** (0.030)	-0,077*** (0.008)	-0,067*** (0.016)
	EDU	-0.047** (0.017)	-0.085** (0.039)	-0.723*** (0.043)	-0.743*** (0.116)	-0,056* (0.031)	-0.091*** (0.032)	0.054*** (0.020)	-0,042** (0.023)
	INF	0.012*** (0.003)	0.012** (0.006)	0.016*** (0.002)	0.022*** (0.006)	0,011*** (0.005)	0.029*** (0.011)	0,017*** (0.003)	0,020*** (0.007)
	FDI	0.010*** (0.001)	0.016*** (0.003)	0.022*** (0.001)	0.028*** (0.004)	0,010*** (0.002)	0.013** (0.005)	0,017*** (0.003)	0.014*** (0.006)
	POP	0.077*** (0.003)	0.086*** (0.007)	0.021 (0.034)	0.007 (0.042)	0,066* (0.034)	0.030 (-0.082)	0.017 (0.021)	0,017 (0.047)
	WAGE	0.002 (0.008)	0.013 (0.018)	0.009 (0.006)	0.022 (0.020)	-0,036** (0.014)	-0.039 (0.033)	-0,005 (0.009)	0.007 (0.018)
	BAG	0.334*** (0.027)	0.328*** (0.060)	-0.007 (0.025)	-0.009 (0.077)	0,163*** (0.053)	0.085 (0.108)	0,593*** (0.038)	0,490*** (0.072)
	LAN	0.003 (0.007)	-0.018 (0.017)	-0.000 (0.005)	-0.022 (0.016)	0,011 (0.013)	-0.003 (0.030)	0,010 (0.008)	-0,024 (0.018)
	DIS	0.000* (0.000)	-0.019 (0.013)	-0.000 (0.000)	-0.021* (0.012)	0.000 (0.000)	-0.031 (0.022)	0.000 (0.000)	-0,023 0.013
	BORDER	0.011 (0.010)	0.028 (0.025)	-0.001 (0.007)	0.035 (0.023)	0,038** (0.018)	0.073* (0.044)	0,010 (0.012)	0,022 (0.025)

" "

This index is constructed by[START_REF] Sachs | Economic reform and the process of global integration[END_REF], is a dummy variable for openness based on five individual dummies for specific trade-related policies. Relying on this index, a country is classified as closed if it displays at least one of the following characteristics: Average tariff rates of 40 percent or more; Non-tariff barriers covering 40 percent or more of trade; A black market exchange rate that is depreciated by

percent or more relative to the official exchange rate, on average, during the 1970s or 1980s; A state monopoly on major exports; A socialist economic system.

FDI flows (i) between developed countries, (ii) between developing countries and (iii) between developed and developing countries.

The KAOPEN index is the[START_REF] Chinn | What matters for financial development? Capital controls, institutions and interactions[END_REF] index of capital account openness. The authors constructed this measure from four binary dummy variables that codify restrictions on cross-border financial transactions reported in the IMF's Annual Reports on Exchange Arrangements and Exchange Restrictions.