Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-10066

MVCC: Missing key and value constraint validation for MVCC tables

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: mvcc
    • Labels:
      None

      Description

      It seems that key and value constraints for MVCC tables are ignoring now when code approach is using to operate with table. The same SQL requests work fine.

      It seems that QueryTypeDescriptorImpl.validateKeyAndValue method call which provides corresponding constraints is missed now.

       

      Reproducer for not null constraint:

      public class IgniteCacheTransactionalSnapshotNullConstraintTest extends GridCommonAbstractTest {
          private static final String REPLICATED_CACHE_NAME = "replicatedCacheName";
      
          private static final String PARTITIONED_CACHE_NAME = "partitionedCacheName";
      
          @Override protected void beforeTestsStarted() throws Exception {
              startGrid(0);
      
              execSQL("CREATE TABLE table(id INT PRIMARY KEY, str VARCHAR NOT NULL) WITH \"atomicity=transactional_snapshot\"");
      
              jcache(grid(0), cacheConfiguration(REPLICATED, TRANSACTIONAL_SNAPSHOT), REPLICATED_CACHE_NAME);
      
              jcache(grid(0), cacheConfiguration(PARTITIONED, TRANSACTIONAL_SNAPSHOT), PARTITIONED_CACHE_NAME);
          }
      
          protected CacheConfiguration cacheConfiguration(CacheMode cacheMode, CacheAtomicityMode atomicityMode) {
              CacheConfiguration cfg = new CacheConfiguration();
      
              cfg.setCacheMode(cacheMode);
              cfg.setAtomicityMode(atomicityMode);
              cfg.setWriteSynchronizationMode(FULL_SYNC);
              cfg.setQueryEntities(Collections.singletonList(new QueryEntity(Integer.class, Person.class)));
      
              return cfg;
          }
      
          public void testPutNullValueReplicatedModeFail() throws Exception {
              IgniteCache<Integer, Person> cache = jcache(0, REPLICATED_CACHE_NAME);
      
              assertThrowsWithCause(() -> {
                  cache.put(0, new Person(null, 25));
              }, IgniteException.class);
          }
      
          public void testPutNullValuePartitionedModeFail() throws Exception {
              IgniteCache<Integer, Person> cache = jcache(0, PARTITIONED_CACHE_NAME);
      
              assertThrowsWithCause(() -> {
                  cache.put(1, new Person(null, 18));
              }, IgniteException.class);
          }
      
          public void testPutNullValueSQLFail() throws Exception {
              checkSQLThrows("INSERT INTO table VALUES(?, ?)", NULL_VALUE, 0, null);
          }
      
          public static class Person implements Serializable {
              @QuerySqlField(notNull = true)
              private String name;
      
              @QuerySqlField
              private int age;
      
              public Person(String name, int age) {
                  this.name = name;
                  this.age = age;
              }
          }
      
          private void checkSQLThrows(String sql, String sqlStateCode, Object... args) {
              IgniteSQLException err = (IgniteSQLException)GridTestUtils.assertThrowsWithCause(() -> {
                  execSQL(sql, args);
      
                  return 0;
              }, IgniteSQLException.class);
      
              assertEquals((err).sqlState(), sqlStateCode);
          }
      
          private List<?> execSQL(String sql, Object... args) {
              SqlFieldsQuery qry = new SqlFieldsQuery(sql)
                  .setArgs(args);
      
              return grid(0).context().query().querySqlFields(qry, true).getAll();
          }
      }
      

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                PetrovMikhail Mikhail Petrov
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: