This method is called in the rolling transaction flow.
This method creates duplicate segments for transaction epoch. It then merges all transactions from the list into
those duplicate segments.
163079
private CompletableFuture<Void> copyTxnEpochSegmentsAndCommitTxns(String scope, String stream, List<UUID> transactionsToCommit,
                                                                      List<Long> segmentIds) {
        // 1. create duplicate segments
        // 2. merge transactions in those segments
        // 3. seal txn epoch segments
        String delegationToken = streamMetadataTasks.retrieveDelegationToken();
        CompletableFuture<Void> createSegmentsFuture = Futures.allOf(segmentIds.stream().map(segment -> {
            // Use fixed scaling policy for these segments as they are created, merged into and sealed and are not
            // supposed to auto scale.
            return streamMetadataTasks.notifyNewSegment(scope, stream, segment, ScalingPolicy.fixed(1), delegationToken);
        }).collect(Collectors.toList()));

        return createSegmentsFuture
                .thenCompose(v -> {
                    log.debug("Rolling transaction, successfully created duplicate txn epoch {} for stream {}/{}", segmentIds, scope, stream);
                    // now commit transactions into these newly created segments
                    return commitTransactions(scope, stream, segmentIds, transactionsToCommit);
                })
                .thenCompose(v -> streamMetadataTasks.notifySealedSegments(scope, stream, segmentIds, delegationToken));
    }
809997
def append_segment(self, apdu):
        """"""
        if _debug: SSM._debug("append_segment %r", apdu)

        # check for no context
        if not self.segmentAPDU:
            raise RuntimeError("no segmentation context established")

        # append the data
        self.segmentAPDU.put_data(apdu.pduData)
70702
private void processNewOperation(StorageOperation operation) {
        if (operation instanceof MergeSegmentOperation) {
            this.operations.add(operation);
            this.mergeTransactionCount.incrementAndGet();
        } else if (operation instanceof StreamSegmentSealOperation) {
            this.operations.add(operation);
            this.hasSealPending.set(true);
        } else if (operation instanceof StreamSegmentTruncateOperation) {
            this.operations.add(operation);
            this.truncateCount.incrementAndGet();
        } else if (operation instanceof CachedStreamSegmentAppendOperation) {
            // Aggregate the Append Operation.
            AggregatedAppendOperation aggregatedAppend = getOrCreateAggregatedAppend(
                    operation.getStreamSegmentOffset(), operation.getSequenceNumber());
            aggregateAppendOperation((CachedStreamSegmentAppendOperation) operation, aggregatedAppend);
        }
    }
303141
private void transferSemiUnique(SemiUniqueEntry[] src, SemiUniqueEntry[] dest) {
        for (int j = 0; j < src.length; ++j)
        {
            SemiUniqueEntry e = src[j];
            src[j] = null;
            while (e != null)
            {
                SemiUniqueEntry next = e.getSemiUniqueNext();
                int i = indexFor(e.getSemiUniqueHash(), dest.length);
                e.setSemiUniqueNext(dest[i]);
                dest[i] = e;
                e = next;
            }
        }
    }
937103
public int[] mergeChunks() {
        int filledChunks = getFilledChunks();
        int[] merged = new int[size()];
        for (int i = 0; i < filledChunks ; i++) {
            if (chunks[i]!=null) {
                System.arraycopy(chunks[i], 0, merged, i * chunkSize, chunkSize);
            }
        }
        int remainder = size() % chunkSize;
        if (remainder != 0 && chunks[filledChunks]!=null) {
            System.arraycopy(chunks[filledChunks], 0, merged, (filledChunks) * chunkSize, remainder);
        }
        return merged;
    }
105280
protected boolean mergeSegments() {
		// can't merge a single line
		if( splits.size <= 2 )
			return false;

		boolean change = false;
		work.reset();

		// first point is always at the start
		work.add(splits.data[0]);

		for( int i = 0; i < splits.size-2; i++ ) {
			if( selectSplitBetween(splits.data[i],splits.data[i+2]) < 0 ) {
				// merge the two lines by not adding it
				change = true;
			} else {
				work.add(splits.data[i + 1]);
			}
		}

		// and end
		work.add(splits.data[splits.size-1]);

		// swap the two lists
		GrowQueue_I32 tmp = work;
		work = splits;
		splits = tmp;

		return change;
	}
1072790
def make_transaction(self):
        
        if self.pk:
            raise CannotRecreateTransactionOnRecurredCost(
                'The transaction for this recurred cost has already been created. You cannot create it again.'
            )

        amount = self.recurring_cost.get_amount(self.billing_cycle)

        # It is quite possible that there will be nothing to bill, in which
        # case we cannot create a transaction with no legs, nor can we create
        # legs with zero values. Therefore we don't create any transaction.
        if not amount:
            return None

        self.transaction = Transaction.objects.create(
            description='Created by recurring cost',
            date=self.billing_cycle.date_range.lower
        )

        # Use the SplitManager's custom queryset's split() method to get the
        # amount to be billed for each split
        splits = self.recurring_cost.splits.all().split(amount)

        # Create the transaction leg for the outbound funds
        # (normally to an expense account)
        self.transaction.legs.add(Leg.objects.create(
            transaction=self.transaction,
            amount=Money(amount, self.recurring_cost.currency),
            account=self.recurring_cost.to_account,
        ))

        for split, split_amount in splits:
            # Create the transaction legs for the inbound funds
            # (from housemate accounts)
            if split_amount:
                self.transaction.legs.add(Leg.objects.create(
                    transaction=self.transaction,
                    amount=Money(split_amount * -1, self.recurring_cost.currency),
                    account=split.from_account,
                ))

        return self.transaction
436490
public final void merge(TransactionStatistics transactionStatistics) {
      if (trace) {
         log.tracef("Merge transaction statistics %s to the node statistics", transactionStatistics);
      }
      ReservoirSampler reservoirSampler;
      ExtendedStatistic percentileSample;
      if (transactionStatistics.isLocalTransaction()) {
         if (transactionStatistics.isReadOnly()) {
            reservoirSampler = percentiles.get(RO_LOCAL_EXECUTION);
            percentileSample = transactionStatistics.isCommitted() ? RO_TX_SUCCESSFUL_EXECUTION_TIME :
                  RO_TX_ABORTED_EXECUTION_TIME;
         } else {
            reservoirSampler = percentiles.get(WR_LOCAL_EXECUTION);
            percentileSample = transactionStatistics.isCommitted() ? WR_TX_SUCCESSFUL_EXECUTION_TIME :
                  WR_TX_ABORTED_EXECUTION_TIME;
         }
      } else {
         if (transactionStatistics.isReadOnly()) {
            reservoirSampler = percentiles.get(RO_REMOTE_EXECUTION);
            percentileSample = transactionStatistics.isCommitted() ? RO_TX_SUCCESSFUL_EXECUTION_TIME :
                  RO_TX_ABORTED_EXECUTION_TIME;
         } else {
            reservoirSampler = percentiles.get(WR_REMOTE_EXECUTION);
            percentileSample = transactionStatistics.isCommitted() ? WR_TX_SUCCESSFUL_EXECUTION_TIME :
                  WR_TX_ABORTED_EXECUTION_TIME;
         }
      }
      doMerge(transactionStatistics, reservoirSampler, percentileSample);
   }
703299
def _join(segments):
    """"""
    new = []
    start = segments[0][0]
    end = segments[0][1]
    for i in range(len(segments)-1):
        if segments[i+1][0] != segments[i][1]:
            new.append((start, end))
            start = segments[i+1][0]
        end = segments[i+1][1]
    new.append((start, end))
    return new
180691
protected void prepareTransactionMemoriesIfExists() {
        final SavedTransactionMemories memories = ThreadCacheContext.findTransactionMemories();
        if (memories != null) {
            final List<TransactionMemoriesProvider> providerList = memories.getOrderedProviderList();
            final StringBuilder sb = new StringBuilder();
            for (TransactionMemoriesProvider provider : providerList) {
                provider.provide().ifPresent(result -> sb.append("\n*").append(result));
            }
            final WholeShowAttribute attribute = new WholeShowAttribute(sb.toString().trim());
            requestManager.setAttribute(LastaWebKey.DBFLUTE_TRANSACTION_MEMORIES_KEY, attribute);
        }
    }
1193692
@Override
    public Operation prepareReplicationOperation(PartitionReplicationEvent event) {
        if (event.getReplicaIndex() > 1) {
            return null;
        }

        List<XATransactionDTO> migrationData = new ArrayList<XATransactionDTO>();
        InternalPartitionService partitionService = nodeEngine.getPartitionService();
        for (Map.Entry<SerializableXID, List<XATransaction>> entry : transactions.entrySet()) {
            SerializableXID xid = entry.getKey();
            int partitionId = partitionService.getPartitionId(xid);
            List<XATransaction> xaTransactionList = entry.getValue();
            for (XATransaction xaTransaction : xaTransactionList) {
                if (partitionId == event.getPartitionId()) {
                    migrationData.add(new XATransactionDTO(xaTransaction));
                }
            }
        }
        if (migrationData.isEmpty()) {
            return null;
        } else {
            return new XaReplicationOperation(migrationData, event.getPartitionId(), event.getReplicaIndex());
        }
    }
1257667
void mergeRolledBackTransaction(Object[] list, int start, int limit) {

        for (int i = start; i < limit; i++) {
            RowAction rowact = (RowAction) list[i];

            if (rowact == null || rowact.type == RowActionBase.ACTION_NONE
                    || rowact.type == RowActionBase.ACTION_DELETE_FINAL) {
                continue;
            }

            Row row = rowact.memoryRow;

            if (row == null) {
                PersistentStore store =
                    rowact.session.sessionData.getRowStore(rowact.table);

                row = (Row) store.get(rowact.getPos(), false);
            }

            if (row == null) {
                continue;
            }

            synchronized (row) {
                rowact.mergeRollback(row);
            }
        }

//        } catch (Throwable t) {
//            System.out.println("throw in merge");
//            t.printStackTrace();
//        }
    }
945899
def add_transaction(self, transaction):
        
        for item in transaction:
            if item not in self.__transaction_index_map:
                self.__items.append(item)
                self.__transaction_index_map[item] = set()
            self.__transaction_index_map[item].add(self.__num_transaction)
        self.__num_transaction += 1
700805
public void createUniqueData()
    {
        LoginGenerator.LoginRecord unique_login;
        unique_login = random_login_generator.createUniqueLogin("voltdb", true);
        doLogin(unique_login);
        unique_login = random_login_generator.createUniqueLogin("voltdb2", false);
        doLogin(unique_login);
    }
933914
def deduplicate_sequences(records, out_file):
    

    logging.info('Applying _deduplicate_sequences generator: '
                 'removing any duplicate records with identical sequences.')
    checksum_sequences = collections.defaultdict(list)
    for record in records:
        checksum = seguid(record.seq)
        sequences = checksum_sequences[checksum]
        if not sequences:
            yield record
        sequences.append(record.id)

    if out_file is not None:
        with out_file:
            for sequences in checksum_sequences.values():
                out_file.write('%s\n' % (' '.join(sequences),))
102606
private void copyPredicates() {
    predicates = new ArrayList<>(groups.size());
    for (List<Segment> group : groups) {
      List<OffsetPredicate> groupPredicates = new ArrayList<>(group.size());
      for (Segment segment : group) {
        groupPredicates.add(segment.offsetPredicate().copy());
      }
      predicates.add(groupPredicates);
    }
  }
477489
public static void mergeInstances(Map<TriangulationPoint, TriangulationPoint> uniquePts, List<TriangulationPoint> ptList) {
        for(int idPoint = 0; idPoint < ptList.size(); idPoint++) {
            TriangulationPoint pt = ptList.get(idPoint);
            TriangulationPoint uniquePt = uniquePts.get(pt);
            if(uniquePt == null) {
                uniquePts.put(pt, pt);
            } else {
                // Duplicate point
                ptList.set(idPoint, uniquePt);
            }
        }
    }