Skip to content

Commit

Permalink
Adding column name validation in tandem with checksum validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumanth Pasupuleti authored and sumanth-pasupuleti committed Feb 11, 2020
1 parent 0227f85 commit a21b3f4
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import com.netflix.astyanax.model.Column;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -131,7 +132,16 @@ public String readSingle(String key) throws Exception {
{
for (int i = 0; i < result.size(); i++)
{
String value = result.getColumnByIndex(i).getStringValue();
Column<Integer> column = result.getColumnByIndex(i);

// validate column name
if (column.getName() != i)
{
throw new Exception(String.format("Column name %d does not match with the expected column name %d", column.getName(), i));
}

// validate column value checksum
String value = column.getStringValue();
if (!CheckSumUtil.isChecksumValid(value))
{
throw new Exception(String.format("Value %s is corrupt. Key %s.", value, key));
Expand Down

0 comments on commit a21b3f4

Please sign in to comment.