grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Error insert query over Grails on docker

Open JJAM2014 opened this issue 2 years ago • 5 comments

Expected Behavior

The application is in grails 4 version and works on a docker with this docker file

FROM adoptopenjdk/openjdk12-openj9

RUN apt full-upgrade
ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n
COPY app.jar app.jar
COPY local_environment/local_config local_config
ENTRYPOINT ["java","-Xmx8192m","-Xms2048m","-XX:-TieredCompilation","-XX:+UseG1GC","-XX:+UseCGroupMemoryLimitForHeap","-XX:+UseStringDeduplication","- XX:+IdleTuningGcOnIdle","-Xtune:virtualized","-Xscmx128m","-Xscmaxaot100m","-XX:+UseContainerSupport","-Djava.security.egd=file:/dev/./urandom"," -DConfigLocation=/xxxx_config","-jar","/app.jar"]
EXPOSE 8000

When I have migrated the application to version 5 it should continue to work

Actual Behaviour

The problem comes because when a query with many inserts is made from

def db = new Sql(dataSource)
db.executeInsert(sqlScript)

docker stops working with grails version 5 and groovy 3.0.7

However, if the JAR is launched java -jar app.jar inside a docker from ubuntu image for instance, there will be not problem when a query is made.

Steps To Reproduce

Inside App with many inserts def db = new Sql(dataSource) b.executeInsert(sqlScript)

Errror Lanch app.jar as a docker FROM adoptopenjdk/openjdk12-openj9

OK Launch app.jar inside docker with linux image

Environment Information

DOCKER EKS JDK 11 grailsVersion=5.1.7 grailsGradlePluginVersion=5.1.3 groovyVersion=3.0.7 gorm.version=7.2.1 org.gradle.daemon=true org.gradle.parallel=true org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx1024M

Example Application

No response

Version

5

JJAM2014 avatar Jun 29 '22 13:06 JJAM2014

Errror Lanch app.jar as a docker FROM adoptopenjdk/openjdk12-openj9

What is the error?

osscontributor avatar Jun 29 '22 16:06 osscontributor

I would appreciate if you could share a sample application.

puneetbehl avatar Jun 30 '22 03:06 puneetbehl

Dear grails team

Method below worked with grails 4.x and groovy 2.x. However, Righ now this method are not working with grails 5.x and groovy 3.x the sorteDimensions list contains a number of domain entities and I think that this will launh many queries, however, before there were not many queris with groovy 2.x

    def batchInsertTable(def tableName, sortedDimensions, batchData) {
        if (batchData) {
            def columnNames = sortedDimensions*.code.join(",")
            String insertInto = "INSERT INTO ${tableName} ( ${columnNames} )"
            def rows = batchData.collect { rowData ->
                def valueArray = []
                sortedDimensions.eachWithIndex { **Dimension** dim, int i ->
                    valueArray.add(castVariableDimension(dim, rowData[i]))
                }
                "(" + valueArray.join(",") + ")"
            }
            String values = " VALUES " + rows.join(", ")
            String sqlScript = insertInto + " " + values
            def db = new Sql(dataSource)
            db.execute(sqlScript as String)
        }
    }

The sortedDimensions list containing domain entities but this example is transformed to a list of Dts. Because it is assumed that the high traffic of queries made to the Dimension table each time it is traversed is what causes the docker to crash.

method used after migration

    void batchInsertTable(def tableName, sortedDimensions, batchData) {
        List sortedDimensionsDto = []
        sortedDimensions.each{ sortedDimension ->
            DimensionDto sortedDimensionDto = new DimensionDto()
            sortedDimensionDto.code = sortedDimension.code
            sortedDimensionDto.dataType = sortedDimension.dataType.code
            sortedDimensionsDto.add(sortedDimensionDto)
        }     
          if (batchData) {
              def columnNames = sortedDimensions*.code.join(",")
              String insertInto = "INSERT INTO ${tableName} ( ${columnNames} )"
              def rows = batchData.collect { rowData ->
                  def valueArray = []
                  sortedDimensionsDto.eachWithIndex { DimensionDto dim, int i ->
                      valueArray.add(castVariableDimension(dim, rowData[i]))
                  }
                  "(" + valueArray.join(",") + ")"
              }
              String values = " VALUES " + rows.join(", ")
              String sqlScript = insertInto + " " + values
              def db = new Sql(dataSource)
              db.execute(sqlScript)
          }
    }

The question is , can the groovy 2.x mode of operation be simulated in groovy 3.x to continue using domain entities in the loops , or will it have to be refactored ?

very thanks in advance

best regards

José

JJAM2014 avatar Jun 30 '22 14:06 JJAM2014

@JJAM2014 Can you share any information about what error is happening?

osscontributor avatar Jun 30 '22 17:06 osscontributor

Dear Jeff, The Error is that docker stops working when execute this method. So, I have only javacore dump file. best regards José

JJAM2014 avatar Jun 30 '22 22:06 JJAM2014