Esempio n. 1
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void Mark()
 {
     if (this._enclosing.GetBackupStore() == null)
     {
         this._enclosing.backupStore = new BackupStore <KEYIN, VALUEIN>(this._enclosing.conf
                                                                        , this._enclosing.taskid);
     }
     this._enclosing.isMarked = true;
     if (!this.inReset)
     {
         this._enclosing.backupStore.Reinitialize();
         if (this._enclosing.currentKeyLength == -1)
         {
             // The user has not called next() for this iterator yet, so
             // there is no current record to mark and copy to backup store.
             return;
         }
         System.Diagnostics.Debug.Assert((this._enclosing.currentValueLength != -1));
         int requestedSize = this._enclosing.currentKeyLength + this._enclosing.currentValueLength
                             + WritableUtils.GetVIntSize(this._enclosing.currentKeyLength) + WritableUtils.GetVIntSize
                                 (this._enclosing.currentValueLength);
         DataOutputStream @out = this._enclosing.backupStore.GetOutputStream(requestedSize
                                                                             );
         this.WriteFirstKeyValueBytes(@out);
         this._enclosing.backupStore.UpdateCounters(requestedSize);
     }
     else
     {
         this._enclosing.backupStore.Mark();
     }
 }
Esempio n. 2
0
 /// <summary>Get the encoded length if an integer is stored in a variable-length format
 ///     </summary>
 /// <returns>the encoded length</returns>
 public static int GetVIntSize(long i)
 {
     return(WritableUtils.GetVIntSize(i));
 }
Esempio n. 3
0
            /// <exception cref="System.IO.IOException"/>
            public virtual void Append(K key, V value)
            {
                if (key.GetType() != keyClass)
                {
                    throw new IOException("wrong key class: " + key.GetType() + " is not " + keyClass
                                          );
                }
                if (value.GetType() != valueClass)
                {
                    throw new IOException("wrong value class: " + value.GetType() + " is not " + valueClass
                                          );
                }
                // Append the 'key'
                keySerializer.Serialize(key);
                int keyLength = buffer.GetLength();

                if (keyLength < 0)
                {
                    throw new IOException("Negative key-length not allowed: " + keyLength + " for " +
                                          key);
                }
                // Append the 'value'
                valueSerializer.Serialize(value);
                int valueLength = buffer.GetLength() - keyLength;

                if (valueLength < 0)
                {
                    throw new IOException("Negative value-length not allowed: " + valueLength + " for "
                                          + value);
                }
                // Write the record out
                WritableUtils.WriteVInt(@out, keyLength);
                // key length
                WritableUtils.WriteVInt(@out, valueLength);
                // value length
                @out.Write(buffer.GetData(), 0, buffer.GetLength());
                // data
                // Reset
                buffer.Reset();
                // Update bytes written
                decompressedBytesWritten += keyLength + valueLength + WritableUtils.GetVIntSize(keyLength
                                                                                                ) + WritableUtils.GetVIntSize(valueLength);
                ++numRecordsWritten;
            }
Esempio n. 4
0
            /// <exception cref="System.IO.IOException"/>
            public virtual void Append(DataInputBuffer key, DataInputBuffer value)
            {
                int keyLength = key.GetLength() - key.GetPosition();

                if (keyLength < 0)
                {
                    throw new IOException("Negative key-length not allowed: " + keyLength + " for " +
                                          key);
                }
                int valueLength = value.GetLength() - value.GetPosition();

                if (valueLength < 0)
                {
                    throw new IOException("Negative value-length not allowed: " + valueLength + " for "
                                          + value);
                }
                WritableUtils.WriteVInt(@out, keyLength);
                WritableUtils.WriteVInt(@out, valueLength);
                @out.Write(key.GetData(), key.GetPosition(), keyLength);
                @out.Write(value.GetData(), value.GetPosition(), valueLength);
                // Update bytes written
                decompressedBytesWritten += keyLength + valueLength + WritableUtils.GetVIntSize(keyLength
                                                                                                ) + WritableUtils.GetVIntSize(valueLength);
                ++numRecordsWritten;
            }
Esempio n. 5
0
        /// <exception cref="System.IO.IOException"/>
        private long WriteRecords(int count, bool knownKeyLength, bool knownValueLength,
                                  bool close)
        {
            long rawDataSize = 0;

            for (int nx = 0; nx < count; nx++)
            {
                string           key    = TestTFileByteArrays.ComposeSortedKey("key", nx);
                DataOutputStream outKey = writer.PrepareAppendKey(knownKeyLength ? key.Length : -
                                                                  1);
                outKey.Write(Runtime.GetBytesForString(key));
                outKey.Close();
                string           value    = "value" + nx;
                DataOutputStream outValue = writer.PrepareAppendValue(knownValueLength ? value.Length
                                         : -1);
                outValue.Write(Runtime.GetBytesForString(value));
                outValue.Close();
                rawDataSize += WritableUtils.GetVIntSize(Runtime.GetBytesForString(key).Length
                                                         ) + Runtime.GetBytesForString(key).Length + WritableUtils.GetVIntSize(Runtime.GetBytesForString
                                                                                                                                   (value).Length) + Runtime.GetBytesForString(value).Length;
            }
            if (close)
            {
                CloseOutput();
            }
            return(rawDataSize);
        }