forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from henningandersen/spacetime_transactions_pre…
…pare Prepare commit phase transport layer
- Loading branch information
Showing
12 changed files
with
530 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
server/src/main/java/org/elasticsearch/action/bulk/ShardPrepareCommitAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.bulk; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
public class ShardPrepareCommitAction extends ActionType<ShardPrepareCommitResponse> { | ||
|
||
public static final ShardPrepareCommitAction INSTANCE = new ShardPrepareCommitAction(); | ||
// todo: should the name be bulk[prepare] style? | ||
public static final String NAME = "indices:data/write/prepare"; | ||
|
||
private ShardPrepareCommitAction() { | ||
super(NAME, ShardPrepareCommitResponse::new); | ||
} | ||
|
||
// todo: transport options? | ||
} |
46 changes: 46 additions & 0 deletions
46
server/src/main/java/org/elasticsearch/action/bulk/ShardPrepareCommitRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.bulk; | ||
|
||
import org.elasticsearch.action.support.replication.ReplicatedWriteRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.index.shard.ShardId; | ||
|
||
import java.io.IOException; | ||
|
||
// todo: make this a per node request. | ||
public class ShardPrepareCommitRequest extends ReplicatedWriteRequest<ShardPrepareCommitRequest> { | ||
private TxID txID; | ||
|
||
public ShardPrepareCommitRequest(ShardId shardId, TxID txID) { | ||
super(shardId); | ||
this.txID = txID; | ||
} | ||
|
||
public ShardPrepareCommitRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.txID = new TxID(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
txID.writeTo(out); | ||
} | ||
|
||
public TxID txid() { | ||
return txID; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + shardId + "," + txID + "]"; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
server/src/main/java/org/elasticsearch/action/bulk/ShardPrepareCommitResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.bulk; | ||
|
||
import org.elasticsearch.action.support.WriteResponse; | ||
import org.elasticsearch.action.support.replication.ReplicationResponse; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class ShardPrepareCommitResponse extends ReplicationResponse implements WriteResponse { | ||
|
||
// initally, we could make do with just a boolean here, but in further iterations, some extra info could be useful. | ||
private final Map<TxID, Boolean> conflicts; | ||
|
||
public ShardPrepareCommitResponse(Map<TxID, Boolean> conflicts) { | ||
this.conflicts = conflicts; | ||
} | ||
|
||
public ShardPrepareCommitResponse(StreamInput in) throws IOException { | ||
super(in); | ||
this.conflicts = in.readMap(TxID::new, StreamInput::readBoolean); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeMap(conflicts, (o, k) -> k.writeTo(o), StreamOutput::writeBoolean); | ||
} | ||
|
||
/** | ||
* the conflict map, the boolean indicates true == this tx won it, false indicates that it lost, i.e., the tx in the map won. | ||
*/ | ||
public Map<TxID, Boolean> conflicts() { | ||
return conflicts; | ||
} | ||
|
||
@Override | ||
public void setForcedRefresh(boolean forcedRefresh) { | ||
// this does not refresh currently. | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.