[jira] [Updated] (SOLR-13243) wrong initialization size of Arraylist

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (SOLR-13243) wrong initialization size of Arraylist

JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/SOLR-13243?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

hu xiaodong updated SOLR-13243:
-------------------------------
    Description:
ElectionContext.java
{code:java}

@Override
void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStartMs)
throws KeeperException, InterruptedException, IOException {
// register as leader - if an ephemeral is already there, wait to see if it goes away

String parent = new Path(leaderPath).getParent().toString();
try {
RetryUtil.retryOnThrowable(NodeExistsException.class, 60000, 5000, () -> {
synchronized (lock) {
log.info("Creating leader registration node {} after winning as {}", leaderPath, leaderSeqPath);
List<Op> ops = new ArrayList<>(2);       //HERE SHOULD BE 3 OR MORE

// We use a multi operation to get the parent nodes version, which will
// be used to make sure we only remove our own leader registration node.
// The setData call used to get the parent version is also the trigger to
// increment the version. We also do a sanity check that our leaderSeqPath exists.

ops.add(Op.check(leaderSeqPath, -1));
ops.add(Op.create(leaderPath, Utils.toJSON(leaderProps), zkClient.getZkACLProvider().getACLsToAdd(leaderPath), CreateMode.EPHEMERAL));
ops.add(Op.setData(parent, null, -1));
List<OpResult> results;

results = zkClient.multi(ops, true);
.......
}
{code}
 

  was:
ElectionContext.java
{code:java}
// code placeholder

@Override
void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStartMs)
throws KeeperException, InterruptedException, IOException {
// register as leader - if an ephemeral is already there, wait to see if it goes away

String parent = new Path(leaderPath).getParent().toString();
try {
RetryUtil.retryOnThrowable(NodeExistsException.class, 60000, 5000, () -> {
synchronized (lock) {
log.info("Creating leader registration node {} after winning as {}", leaderPath, leaderSeqPath);
List<Op> ops = new ArrayList<>(2);    //here should be 3 or more

// We use a multi operation to get the parent nodes version, which will
// be used to make sure we only remove our own leader registration node.
// The setData call used to get the parent version is also the trigger to
// increment the version. We also do a sanity check that our leaderSeqPath exists.

ops.add(Op.check(leaderSeqPath, -1));
ops.add(Op.create(leaderPath, Utils.toJSON(leaderProps), zkClient.getZkACLProvider().getACLsToAdd(leaderPath), CreateMode.EPHEMERAL));
ops.add(Op.setData(parent, null, -1));
List<OpResult> results;

results = zkClient.multi(ops, true);
.......
}
{code}
 


> wrong initialization size of Arraylist
> --------------------------------------
>
>                 Key: SOLR-13243
>                 URL: https://issues.apache.org/jira/browse/SOLR-13243
>             Project: Solr
>          Issue Type: Improvement
>      Security Level: Public(Default Security Level. Issues are Public)
>          Components: SolrCloud
>    Affects Versions: 7.7
>            Reporter: hu xiaodong
>            Priority: Trivial
>         Attachments: SOLR-13243.patch
>
>
> ElectionContext.java
> {code:java}
> @Override
> void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStartMs)
> throws KeeperException, InterruptedException, IOException {
> // register as leader - if an ephemeral is already there, wait to see if it goes away
> String parent = new Path(leaderPath).getParent().toString();
> try {
> RetryUtil.retryOnThrowable(NodeExistsException.class, 60000, 5000, () -> {
> synchronized (lock) {
> log.info("Creating leader registration node {} after winning as {}", leaderPath, leaderSeqPath);
> List<Op> ops = new ArrayList<>(2);       //HERE SHOULD BE 3 OR MORE
> // We use a multi operation to get the parent nodes version, which will
> // be used to make sure we only remove our own leader registration node.
> // The setData call used to get the parent version is also the trigger to
> // increment the version. We also do a sanity check that our leaderSeqPath exists.
> ops.add(Op.check(leaderSeqPath, -1));
> ops.add(Op.create(leaderPath, Utils.toJSON(leaderProps), zkClient.getZkACLProvider().getACLsToAdd(leaderPath), CreateMode.EPHEMERAL));
> ops.add(Op.setData(parent, null, -1));
> List<OpResult> results;
> results = zkClient.multi(ops, true);
> .......
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]