@Override public void close() { if (!closed) { closed = true; os.reset(); } } }
@Override public void close() { if (!closed) { closed = true; os.reset(); } } }
@Override public void close() { if (!closed) { closed = true; os.reset(); } } }
private void closeInternal() { os.reset(); } }
private void closeInternal() { os.reset(); } }
private void closeInternal() { os.reset(); } }
private void closeInternal() { os.reset(); } }
private byte[] getSerializedValue( K key, ByteArrayOutputStreamWithPos outputStream, DataOutputView outputView, TypeSerializer<K> keySerializer) throws Exception { outputStream.reset(); byte[] serializedKey = StateSerializerUtil.getSerializedKeyForKeyedValueState( outputStream, outputView, key, keySerializer, getKeyGroup(key), stateNameForSerializer); return (byte[]) stateStorage.get(serializedKey); } }
private byte[] getSerializedValue( K key, ByteArrayOutputStreamWithPos outputStream, DataOutputView outputView, TypeSerializer<K> safeKeySerializer) throws Exception { outputStream.reset(); byte[] serializedKey = StateSerializerUtil.getSerializedKeyForKeyedListState( outputStream, outputView, key, safeKeySerializer, getKeyGroup(key), stateNameForSerialize); return (byte[]) stateStorage.get(serializedKey); } }
private byte[] getSerializedValue( K key, N namespace, ByteArrayOutputStreamWithPos outputStream, DataOutputView outputView, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer) throws Exception { outputStream.reset(); byte[] serializedKey = StateSerializerUtil.getSerializedKeyForSubKeyedListState( outputStream, outputView, key, keySerializer, namespace, namespaceSerializer, getKeyGroup(key), stateNameForSerialize); return (byte[]) stateStorage.get(serializedKey); }
private byte[] getSerializedValue( K key, N namespace, ByteArrayOutputStreamWithPos outputStream, DataOutputView outputView, TypeSerializer<K> keySerializer, TypeSerializer<N> safeNamespaceSerializer) throws Exception { outputStream.reset(); byte[] serializedKey = StateSerializerUtil.getSerializedKeyForSubKeyedValueState( outputStream, outputView, key, keySerializer, namespace, safeNamespaceSerializer, getKeyGroup(key), stateNameForSerialize); return (byte[]) stateStorage.get(serializedKey); }
private byte[] serializeUserValue(UV userValue) throws IOException { keySerializationStream.reset(); if (userValue == null) { keySerializationDataOutputView.writeBoolean(true); } else { keySerializationDataOutputView.writeBoolean(false); userValueSerializer.serialize(userValue, keySerializationDataOutputView); } return keySerializationStream.toByteArray(); }
protected void writeKeyWithGroupAndNamespace( int keyGroup, K key, N namespace, ByteArrayOutputStreamWithPos keySerializationStream, DataOutputView keySerializationDataOutputView) throws IOException { Preconditions.checkNotNull(key, "No key set. This method should not be called outside of a keyed context."); keySerializationStream.reset(); writeKeyGroup(keyGroup, keySerializationDataOutputView); writeKey(key, keySerializationStream, keySerializationDataOutputView); writeNameSpace(namespace, keySerializationStream, keySerializationDataOutputView); }
@Override public void add(V value) throws IOException { try { writeCurrentKeyWithGroupAndNamespace(); byte[] key = keySerializationStream.toByteArray(); keySerializationStream.reset(); DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(keySerializationStream); valueSerializer.serialize(value, out); backend.db.merge(columnFamily, writeOptions, key, keySerializationStream.toByteArray()); } catch (Exception e) { throw new RuntimeException("Error while adding data to RocksDB", e); } }
/** * Decode a bigint value. */ public BigInteger decodeBigInteger(DataInputView source, Order ord) throws IOException { // skip the first 4 bytes which is only used for sort source.skipBytes(4); if (reuseBuffer == null) { reuseBuffer = new byte[BUFFER_SIZE]; } if (reuseBaos == null) { reuseBaos = new ByteArrayOutputStreamWithPos(); } reuseBaos.reset(); int len; while ((len = source.read(reuseBuffer)) != -1) { reuseBaos.write(reuseBuffer, 0, len); } return new BigInteger(ord.apply(reuseBaos.toByteArray())); }
@Override public void add(V value) throws IOException { try { writeCurrentKeyWithGroupAndNamespace(); byte[] key = keySerializationStream.toByteArray(); byte[] valueBytes = backend.db.get(columnFamily, key); DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(keySerializationStream); if (valueBytes == null) { keySerializationStream.reset(); valueSerializer.serialize(value, out); backend.db.put(columnFamily, writeOptions, key, keySerializationStream.toByteArray()); } else { V oldValue = valueSerializer.deserialize(new DataInputViewStreamWrapper(new ByteArrayInputStream(valueBytes))); V newValue = reduceFunction.reduce(oldValue, value); keySerializationStream.reset(); valueSerializer.serialize(newValue, out); backend.db.put(columnFamily, writeOptions, key, keySerializationStream.toByteArray()); } } catch (Exception e) { throw new RuntimeException("Error while adding data to RocksDB", e); } }
@Override public void update(V value) throws IOException { if (value == null) { clear(); return; } DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(keySerializationStream); try { writeCurrentKeyWithGroupAndNamespace(); byte[] key = keySerializationStream.toByteArray(); keySerializationStream.reset(); valueSerializer.serialize(value, out); backend.db.put(columnFamily, writeOptions, key, keySerializationStream.toByteArray()); } catch (Exception e) { throw new RuntimeException("Error while adding data to RocksDB", e); } } }
@Override public int compare(T left, T right) { ByteArrayOutputStreamWithPos outputStream = new ByteArrayOutputStreamWithPos(); DataOutputViewStreamWrapper outputView = new DataOutputViewStreamWrapper(outputStream); try { serializer.serialize(left, outputView); byte[] leftBytes = outputStream.toByteArray(); outputStream.reset(); serializer.serialize(right, outputView); byte[] rightBytes = outputStream.toByteArray(); return compareBytes(leftBytes, rightBytes); } catch (IOException e) { throw new SerializationException(e); } }
@Override public void add(T value) throws IOException { try { writeCurrentKeyWithGroupAndNamespace(); byte[] key = keySerializationStream.toByteArray(); byte[] valueBytes = backend.db.get(columnFamily, key); DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(keySerializationStream); if (valueBytes == null) { keySerializationStream.reset(); valueSerializer.serialize(foldFunction.fold(stateDesc.getDefaultValue(), value), out); backend.db.put(columnFamily, writeOptions, key, keySerializationStream.toByteArray()); } else { ACC oldValue = valueSerializer.deserialize(new DataInputViewStreamWrapper(new ByteArrayInputStreamWithPos(valueBytes))); ACC newValue = foldFunction.fold(oldValue, value); keySerializationStream.reset(); valueSerializer.serialize(newValue, out); backend.db.put(columnFamily, writeOptions, key, keySerializationStream.toByteArray()); } } catch (Exception e) { throw new RuntimeException("Error while adding data to RocksDB", e); } }