Creates a new UpdateableSegmentMetadata for the given Segment and registers it.
2617
private UpdateableSegmentMetadata createSegmentMetadata(String segmentName, long segmentId) {
        UpdateableSegmentMetadata metadata = new StreamSegmentMetadata(segmentName, segmentId, this.containerId);
        this.newSegments.put(metadata.getId(), metadata);
        this.newSegmentNames.put(metadata.getName(), metadata.getId());
        return metadata;
    }
234032
@Override
  public Set<DataSegment> perform(Task task, TaskActionToolbox toolbox)
  {
    return new SegmentTransactionalInsertAction(segments, null, null).perform(task, toolbox).getSegments();
  }
659622
private Segment loadDiskSegment(long segmentId, long segmentVersion) {
    File file = SegmentFile.createSegmentFile(name, storage.directory(), segmentId, segmentVersion);
    Buffer buffer = FileBuffer.allocate(file, Math.min(DEFAULT_BUFFER_SIZE, storage.maxSegmentSize()), Integer.MAX_VALUE);
    SegmentDescriptor descriptor = new SegmentDescriptor(buffer);
    Segment segment = new Segment(new SegmentFile(file), buffer.position(SegmentDescriptor.BYTES).slice(), descriptor, createIndex(descriptor), new OffsetPredicate(), serializer.clone(), this);
    LOGGER.debug("Loaded file segment: {} ({})", descriptor.id(), file.getName());
    return segment;
  }
221499
private void updateMetadata(SegmentProperties segmentProperties) {
        this.metadata.setStorageLength(segmentProperties.getLength());
        if (segmentProperties.isSealed() && !this.metadata.isSealedInStorage()) {
            this.metadata.markSealed();
            this.metadata.markSealedInStorage();
        }
    }
774927
protected function createSegment() {
		$this->shm = shmop_open(
			$this->getIdentifier(),
			self::SHM_CREATE_MODE,
			self::SHM_CREATE_PERMISSIONS,
			$this->size
		);

		if (false === $this->shm) {
			throw new RuntimeException(sprintf('Unable to create shared memory segment with key: %s', $this->getIdentifier()));
		}

		$this->updateSize(0);
	}
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)
662022
void apply(UpdateableSegmentMetadata target) {
        if (!this.isChanged) {
            // No changes made.
            return;
        }

        Preconditions.checkArgument(target.getId() == this.id,
                "Target Segment Id mismatch. Expected %s, given %s.", this.id, target.getId());
        Preconditions.checkArgument(target.getName().equals(this.name),
                "Target Segment Name mismatch. Expected %s, given %s.", name, target.getName());

        // Apply to base metadata.
        target.setLastUsed(this.lastUsed);
        target.updateAttributes(this.attributeUpdates);
        target.setLength(this.length);

        // Update StartOffset after (potentially) updating the length, since he Start Offset must be less than or equal to Length.
        target.setStartOffset(this.startOffset);
        if (this.storageLength >= 0) {
            // Only update this if it really was set. Otherwise we might revert back to an old value if the Writer
            // has already made progress on it.
            target.setStorageLength(this.storageLength);
        }

        if (this.sealed) {
            target.markSealed();
            if (this.sealedInStorage) {
                target.markSealedInStorage();
            }
        }

        if (this.merged) {
            target.markMerged();
        }

        if (this.deleted) {
            target.markDeleted();
            if (this.deletedInStorage) {
                target.markDeletedInStorage();
            }
        }

        if (this.pinned) {
            target.markPinned();
        }
    }
374917
private Segment nextSegment(boolean newOnly) throws IOException {
        int index;
        Segment seg;

        if (newOnly) {
            index = _segList.size();
        } else {
            if (_recycleList.size() > 0) {
                seg = _recycleList.remove();
                seg.reinit();

                _segList.set(seg.getSegmentId(), seg);
                _log.info("reinit Segment " + seg.getSegmentId());
                return seg;
            }

            for (index = 0; index < _segList.size(); index++) {
                if (_segList.get(index) == null)
                    break;
            }
        }

        // Always create next segment as READ_WRITE
        File segFile = getSegmentFile(index);
        seg = getSegmentFactory().createSegment(index, segFile, _segFileSizeMB, Segment.Mode.READ_WRITE);

        if (index < _segList.size())
            _segList.set(index, seg);
        else
            _segList.add(seg);

        return seg;
    }
1166489
public synchronized Segment nextSegment() {
    assertOpen();
    Segment lastSegment = lastSegment();
    SegmentDescriptor descriptor = SegmentDescriptor.builder()
      .withId(lastSegment != null ? lastSegment.descriptor().id() + 1 : 1)
      .withVersion(1)
      .withIndex(currentSegment.lastIndex() + 1)
      .withMaxSegmentSize(storage.maxSegmentSize())
      .withMaxEntries(storage.maxEntriesPerSegment())
      .build();
    descriptor.lock();

    currentSegment = createSegment(descriptor);

    segments.put(descriptor.index(), currentSegment);
    return currentSegment;
  }
735724
public static void copyToView(
			MemorySegment[] segments,
			int offset,
			int sizeInBytes,
			DataOutputView target) throws IOException {
		for (MemorySegment sourceSegment : segments) {
			int curSegRemain = sourceSegment.size() - offset;
			if (curSegRemain > 0) {
				int copySize = Math.min(curSegRemain, sizeInBytes);

				byte[] bytes = allocateReuseBytes(copySize);
				sourceSegment.get(offset, bytes, 0, copySize);
				target.write(bytes, 0, copySize);

				sizeInBytes -= copySize;
				offset = 0;
			} else {
				offset -= sourceSegment.size();
			}

			if (sizeInBytes == 0) {
				return;
			}
		}

		if (sizeInBytes != 0) {
			throw new RuntimeException("No copy finished, this should be a bug, " +
					"The remaining length is: " + sizeInBytes);
		}
	}
1336665
def help_center_user_segment_create(self, data, **kwargs):
        ""
        api_path = "/api/v2/help_center/user_segments.json"
        return self.call(api_path, method="POST", data=data, **kwargs)
2448
def __add_segment(self, segment):
        
        segment_id = self.ns+':'+segment.attrib['id']
        self.edus.append(segment_id)  # store RST segment in list of EDUs

        # A URML file can be tokenized, partially tokenized or not tokenized
        # at all. The "tokenized tokens" in the URML file will always be added
        # to the graph as nodes. The "untokenized tokens" will only be added,
        # if ``self.tokenize`` is ``True``.

        if is_segment_tokenized(segment):
            self.tokenized = True
            segment_text = sanitize_string(
                ' '.join(e.text for e in segment if e.text is not None))

            for i, tok_elem in enumerate(segment):
                tok = tok_elem.text
                self.__add_token(segment_id, i, tok)

        else:  # is_segment_tokenized(segment) is False
            segment_text = sanitize_string(segment.text)
            segment_toks = segment_text.split()

            if self.tokenize:
                self.tokenized = True
                for i, tok in enumerate(segment_toks):
                    self.__add_token(segment_id, i, tok)

        segment_type = self.segment_types[segment_id]
        segment_label = get_segment_label(
            segment, segment_type, segment_text, self.ns, self.tokenize)
        self.add_node(
            segment_id, layers={self.ns, self.ns+':segment'},
            attr_dict={self.ns+':text' : segment_text,
                       'label':  segment_label})
546724
private synchronized void resetCurrentSegment() {
    JournalSegment<E> lastSegment = getLastSegment();
    if (lastSegment != null) {
      currentSegment = lastSegment;
    } else {
      JournalSegmentDescriptor descriptor = JournalSegmentDescriptor.builder()
          .withId(1)
          .withIndex(1)
          .withMaxSegmentSize(maxSegmentSize)
          .withMaxEntries(maxEntriesPerSegment)
          .build();

      currentSegment = createSegment(descriptor);

      segments.put(1L, currentSegment);
    }
  }
587820
protected void fireSegmentAdded(RoadSegment segment) {
		if (this.listeners != null && isEventFirable()) {
			for (final RoadNetworkListener listener : this.listeners) {
				listener.onRoadSegmentAdded(this, segment);
			}
		}
	}
531285
protected function setupSegment() {
		// Attempt to open shm segment
		$this->shm = @shmop_open($this->getIdentifier(), self::SHM_OPEN_MODE, 0, 0);

		// If segment doesn't exist init new segment
		if (false === $this->shm) {
			$this->createSegment();
		}
	}
523969
protected void init() {
        try {
            // Initialize the current working segment
            _segment = _segmentManager.nextSegment();
            
            // Segment index buffer is enabled by default!
            _sib = _segmentManager.openSegmentIndexBuffer(_segment.getSegmentId());
            if(!_sibEnabled) _sib.markAsDirty();
            
            _log.info("Segment " + _segment.getSegmentId() + " online: " + _segment.getStatus());
        } catch(IOException ioe) {
            _log.error(ioe.getMessage(), ioe);
            throw new SegmentException("Instantiation failed due to " + ioe.getMessage());
        }
    }
1164370
private void mergeCompleted(SegmentProperties segmentProperties, UpdateableSegmentMetadata transactionMetadata, MergeSegmentOperation mergeOp) {
        // We have processed a MergeSegmentOperation, pop the first operation off and decrement the counter.
        StorageOperation processedOperation = this.operations.removeFirst();
        assert processedOperation != null && processedOperation instanceof MergeSegmentOperation : "First outstanding operation was not a MergeSegmentOperation";
        MergeSegmentOperation mop = (MergeSegmentOperation) processedOperation;
        assert mop.getSourceSegmentId() == transactionMetadata.getId() : "First outstanding operation was a MergeSegmentOperation for the wrong Transaction id.";
        int newCount = this.mergeTransactionCount.decrementAndGet();
        assert newCount >= 0 : "Negative value for mergeTransactionCount";

        // Post-merger validation. Verify we are still in agreement with the storage.
        long expectedNewLength = this.metadata.getStorageLength() + mergeOp.getLength();
        if (segmentProperties.getLength() != expectedNewLength) {
            throw new CompletionException(new DataCorruptionException(String.format(
                    "Transaction Segment '%s' was merged into parent '%s' but the parent segment has an unexpected StorageLength after the merger. Previous=%d, MergeLength=%d, Expected=%d, Actual=%d",
                    transactionMetadata.getName(),
                    this.metadata.getName(),
                    segmentProperties.getLength(),
                    mergeOp.getLength(),
                    expectedNewLength,
                    segmentProperties.getLength())));
        }

        updateMetadata(segmentProperties);
        updateMetadataForTransactionPostMerger(transactionMetadata, mop.getStreamSegmentId());
    }