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

    https://github.com/apache/incubator-tephra/pull/37#discussion_r102122535
  
    --- Diff: 
tephra-core/src/main/java/org/apache/tephra/manager/InvalidTxList.java ---
    @@ -0,0 +1,110 @@
    +/*
    + * 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 org.apache.tephra.TransactionManager;
    +
    +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 #toArray()} 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 LongArrayList 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);
    +    if (changed && !dirty) {
    +      dirty = true;
    +    }
    +    return changed;
    +  }
    +
    +  public boolean addAll(Collection<? extends Long> ids) {
    +    boolean changed = invalid.addAll(ids);
    +    if (changed && !dirty) {
    +      dirty = true;
    +    }
    +    return changed;
    +  }
    +
    +  public boolean contains(long id) {
    +    return invalid.contains(id);
    +  }
    +
    +  public boolean remove(long id) {
    +    boolean changed = invalid.rem(id);
    +    if (changed && !dirty) {
    +      dirty = true;
    +    }
    +    return changed;
    +  }
    +
    +  public boolean removeAll(Collection<? extends Long> ids) {
    +    boolean changed = invalid.removeAll(ids);
    +    if (changed && !dirty) {
    +      dirty = true;
    +    }
    +    return changed;
    +  }
    +
    +  public void clear() {
    +    invalid.clear();
    +    invalidArray = NO_INVALID_TX;
    +    dirty = false;
    +  }
    +
    +  public long[] toArray() {
    +    if (dirty) {
    +      Collections.sort(invalid);
    +      invalidArray = invalid.toLongArray();
    +      dirty = false;
    +    }
    +    return invalidArray;
    +  }
    +
    +  public List<Long> toList() {
    +    return Collections.unmodifiableList(invalid);
    --- End diff --
    
    This won't be sorted right? But the comment on line 1114 of 
TransactionManager seems to assume that this method return a sorted list?


---
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