Github user chtyim commented on a diff in the pull request:

    https://github.com/apache/incubator-tephra/pull/37#discussion_r102343334
  
    --- Diff: 
tephra-core/src/main/java/org/apache/tephra/manager/InvalidTxList.java ---
    @@ -0,0 +1,127 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.tephra.manager;
    +
    +import it.unimi.dsi.fastutil.longs.LongArrayList;
    +import it.unimi.dsi.fastutil.longs.LongCollection;
    +import it.unimi.dsi.fastutil.longs.LongList;
    +import org.apache.tephra.TransactionManager;
    +
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.List;
    +import javax.annotation.concurrent.NotThreadSafe;
    +
    +/**
    + * This is an internal class used by the {@link TransactionManager} to 
store invalid transaction ids.
    + * This class uses both a list and an array to keep track of the invalid 
ids. The list is the primary
    + * data structure for storing the invalid ids. The array is populated 
lazily on changes to the list.
    + * The array is used to avoid creating a new array every time method 
{@link #toSortedArray()} is invoked.
    + *
    + * This class is not thread safe and relies on external synchronization. 
TransactionManager always
    + * accesses an instance of this class after synchronization.
    + */
    +@NotThreadSafe
    +public class InvalidTxList {
    +  private static final long[] NO_INVALID_TX = { };
    +
    +  private final LongList invalid = new LongArrayList();
    +  private long[] invalidArray = NO_INVALID_TX;
    +
    +  private boolean dirty = false; // used to track changes to the invalid 
list
    +
    +  public int size() {
    +    return invalid.size();
    +  }
    +
    +  public boolean isEmpty() {
    +    return invalid.isEmpty();
    +  }
    +
    +  public boolean add(long id) {
    +    boolean changed = invalid.add(id);
    +    dirty = dirty || changed;
    +    return changed;
    +  }
    +
    +  public boolean addAll(Collection<? extends Long> ids) {
    +    boolean changed = invalid.addAll(ids);
    +    dirty = dirty || changed;
    +    return changed;
    +  }
    +
    +  public boolean addAll(LongCollection ids) {
    --- End diff --
    
    Should use `LongList` instead of `LongCollection` as the `LongArrayList` 
only optimize if it is a `LongList`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to