Skip to content

Commit d73b713

Browse files
committed
add export, list, import commands
1 parent aa5c3ab commit d73b713

17 files changed

+1352
-194
lines changed

src/java/org/apache/cassandra/db/compression/CompressionDictionary.java

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ public interface CompressionDictionary extends AutoCloseable
4949
*/
5050
byte[] rawDictionary();
5151

52+
/**
53+
* Get checksum of this dictionary.
54+
*
55+
* @return checksum of this dictionary
56+
*/
57+
int checksum();
58+
5259
/**
5360
* Get the kind of the compression algorithm
5461
*
@@ -126,7 +133,7 @@ static CompressionDictionary deserialize(DataInput input, @Nullable CompressionD
126133
throw new IOException("Compression dictionary checksum does not match. " +
127134
"Expected: " + checksum + "; actual: " + calculatedChecksum);
128135

129-
CompressionDictionary dictionary = kind.createDictionary(dictId, dict);
136+
CompressionDictionary dictionary = kind.createDictionary(dictId, dict, checksum);
130137

131138
// update the dictionary manager if it exists
132139
if (manager != null)
@@ -137,6 +144,29 @@ static CompressionDictionary deserialize(DataInput input, @Nullable CompressionD
137144
return dictionary;
138145
}
139146

147+
static LightweightCompressionDictionary createFromRowLightweight(UntypedResultSet.Row row)
148+
{
149+
String kindStr = row.getString("kind");
150+
long dictId = row.getLong("dict_id");
151+
int checksum = row.getInt("dict_checksum");
152+
int size = row.getInt("dict_length");
153+
String keyspaceName = row.getString("keyspace_name");
154+
String tableName = row.getString("table_name");
155+
156+
try
157+
{
158+
return new LightweightCompressionDictionary(keyspaceName,
159+
tableName,
160+
new DictId(CompressionDictionary.Kind.valueOf(kindStr), dictId),
161+
checksum,
162+
size);
163+
}
164+
catch (IllegalArgumentException ex)
165+
{
166+
throw new IllegalStateException(kindStr + " compression dictionary is not created for dict id " + dictId);
167+
}
168+
}
169+
140170
static CompressionDictionary createFromRow(UntypedResultSet.Row row)
141171
{
142172
String kindStr = row.getString("kind");
@@ -164,7 +194,7 @@ static CompressionDictionary createFromRow(UntypedResultSet.Row row)
164194
kindStr, dictId, storedChecksum, calculatedChecksum));
165195
}
166196

167-
return kind.createDictionary(new DictId(kind, dictId), dict);
197+
return kind.createDictionary(new DictId(kind, dictId), row.getByteArray("dict"), storedChecksum);
168198
}
169199
catch (IllegalArgumentException ex)
170200
{
@@ -188,9 +218,10 @@ enum Kind
188218
// Order matters: the enum ordinal is serialized
189219
ZSTD
190220
{
191-
public CompressionDictionary createDictionary(DictId dictId, byte[] dict)
221+
@Override
222+
public CompressionDictionary createDictionary(DictId dictId, byte[] dict, int checksum)
192223
{
193-
return new ZstdCompressionDictionary(dictId, dict);
224+
return new ZstdCompressionDictionary(dictId, dict, checksum);
194225
}
195226

196227
@Override
@@ -220,9 +251,10 @@ public ICompressionDictionaryTrainer createTrainer(String keyspaceName,
220251
*
221252
* @param dictId the dictionary identifier
222253
* @param dict the raw dictionary bytes
254+
* @param checksum checksum of this dictionary
223255
* @return a compression dictionary instance
224256
*/
225-
public abstract CompressionDictionary createDictionary(CompressionDictionary.DictId dictId, byte[] dict);
257+
public abstract CompressionDictionary createDictionary(CompressionDictionary.DictId dictId, byte[] dict, int checksum);
226258

227259
/**
228260
* Creates a dictionary compressor for this kind
@@ -281,4 +313,32 @@ public String toString()
281313
'}';
282314
}
283315
}
316+
317+
/**
318+
* The purpose of lightweight dictionary is to not carry the actual dictionary bytes for performance reasons.
319+
* Handy for situations when retrieval from the database does not need to contain dictionary
320+
* or the instantiation of a proper dictionary object is not desirable or unnecessary for other,
321+
* mostly performance-related, reasons.
322+
*/
323+
class LightweightCompressionDictionary
324+
{
325+
public final String keyspaceName;
326+
public final String tableName;
327+
public final DictId dictId;
328+
public final int checksum;
329+
public final int size;
330+
331+
public LightweightCompressionDictionary(String keyspaceName,
332+
String tableName,
333+
DictId dictId,
334+
int checksum,
335+
int size)
336+
{
337+
this.keyspaceName = keyspaceName;
338+
this.tableName = tableName;
339+
this.dictId = dictId;
340+
this.checksum = checksum;
341+
this.size = size;
342+
}
343+
}
284344
}

0 commit comments

Comments
 (0)